我更新了我的應用程序到grails 3.1.9,並且我在數據庫遷移插件時遇到了問題。grails 3數據庫遷移
我生產application.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
我將不勝感激任何想法,爲什麼它不工作。
謝謝Gregor Petkin。設置dbcreate來驗證確實幫助我解決了這個錯誤。
如果你明確地將'dbCreate'設置爲'validate'而不是'none',它有幫助嗎? –
@Gregor Petrin你好,它似乎有幫助。看我的編輯。 –