【发布时间】:2017-01-08 03:36:18
【问题描述】:
我将我的应用程序更新到了 grails 3.1.9,但我在使用数据库迁移插件时遇到了问题。
我的生产应用程序.yml 如下所示:
production:
dataSource:
driverClassName: org.postgresql.Driver
dialect: org.hibernate.dialect.PostgreSQLDialect
dbCreate: none
url: jdbc:postgresql://localhost:5432/something
username: postgres
password: postgres
properties:
我的 build.gradle 看起来像这样:
buildscript {
dependencies {
classpath 'org.grails.plugins:database-migration:2.0.0.RC4'
}
}
dependencies {
compile 'org.liquibase:liquibase-core:3.4.1'
compile 'org.grails.plugins:database-migration:2.0.0.RC4'
}
这是更新日志的开头:
databaseChangeLog = {
changeSet(author: "michal (generated)", id: "1472650791344-1") {
createTable(tableName: "appointment") {
column(autoIncrement: "true", name: "id", type: "BIGINT") {
constraints(primaryKey: "true", primaryKeyName: "appointmentPK")
}
column(name: "version", type: "BIGINT")
column(name: "customer_id", type: "BIGINT")
column(name: "duration", type: "BLOB(255)")
column(name: "note", type: "CLOB")
column(defaultValueComputed: "0", name: "personal_available", type: "BOOLEAN")
column(defaultValueComputed: "0", name: "personal_booked", type: "BOOLEAN")
column(name: "provider_id", type: "BIGINT")
column(name: "start_time", type: "BLOB(255)")
column(name: "url", type: "VARCHAR(255)")
}
}
当我在生产模式下运行我的应用时,我收到了这个错误。
SEVERE 8/31/16 3:41 PM: liquibase: changelog.groovy: changelog.groovy::1472650791344-1::michal (generated): Change Set changelog.groovy::1472650791344-1::michal (generated) failed. Error: ERROR: relation "appointment" already exists [Failed SQL: CREATE TABLE public.appointment (id BIGSERIAL NOT NULL, version BIGINT, customer_id BIGINT, duration BYTEA, note TEXT, personal_available BOOLEAN DEFAULT 0, personal_booked BOOLEAN DEFAULT 0, provider_id BIGINT, start_time BYTEA, url VARCHAR(255), CONSTRAINT "appointmentPK" PRIMARY KEY (id))]
liquibase.exception.DatabaseException: ERROR: relation "appointment" already exists [Failed SQL: CREATE TABLE public.appointment (id BIGSERIAL NOT NULL, version BIGINT, customer_id BIGINT, duration BYTEA, note TEXT, personal_available BOOLEAN DEFAULT 0, personal_booked BOOLEAN DEFAULT 0, provider_id BIGINT, start_time BYTEA, url VARCHAR(255), CONSTRAINT "appointmentPK" PRIMARY KEY (id))]
at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:316)
...
Caused by: org.postgresql.util.PSQLException: ERROR: relation "appointment" already exists
我会感激任何想法,为什么它不起作用。
谢谢格雷戈尔·佩特金。将 dbcreate 设置为 validate 确实帮助我修复了这个错误。
【问题讨论】:
-
如果您将
dbCreate明确设置为validate而不是none,是否有帮助? -
@Gregor Petrin 嗨,它似乎有帮助。查看我的编辑。
标签: grails migration database-migration