我有一個用於客戶的域類。我最近不得不更改爲域名類,因爲我們收集的是帳單郵寄地址和送貨地址,但只記錄了一個郵政編碼值。所以我認爲這是一個簡單的修復。將郵政編碼更改爲billzipcode,然後爲shipzipcode創建一個新字段。我運行dbm-gorm-diff來創建更改日誌,然後運行dbm-update來執行我所做的更改。這一切的一切都在順利進行。但後來我去調試應用程序,看看數據源的變化是好的。但是,現在當我嘗試保存新的客戶記錄它得到這個錯誤:Grails:休眠和數據遷移
NULL not allowed for column "ZIPCODE"; SQL statement:
insert into customer (id, version, billaddr, billcity, billstate, billzipcode, cell, contact, country_id, custcode, custname, date_created, email, fax, last_updated, organization, phone, shipaddr, shipasbill, shipcity, shipstate, shipzipcode, status, tenant_id) values (null, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [23502-164]. Stacktrace follows:
org.h2.jdbc.JdbcSQLException: NULL not allowed for column "ZIPCODE"; SQL statement:
insert into customer (id, version, billaddr, billcity, billstate, billzipcode, cell, contact, country_id, custcode, custname, date_created, email, fax, last_updated, organization, phone, shipaddr, shipasbill, shipcity, shipstate, shipzipcode, status, tenant_id) values (null, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [23502-164]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
at org.h2.message.DbException.get(DbException.java:169)
at org.h2.message.DbException.get(DbException.java:146)
at org.h2.table.Column.validateConvertUpdateSequence(Column.java:293)
at org.h2.table.Table.validateConvertUpdateSequence(Table.java:680)
at org.h2.command.dml.Insert.insertRows(Insert.java:120)
at org.h2.command.dml.Insert.update(Insert.java:84)
at org.h2.command.CommandContainer.update(CommandContainer.java:73)
at org.h2.command.Command.executeUpdate(Command.java:226)
at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:143)
at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:129)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
at com.companyName.appname.billing.CustomerController$_closure6.doCall(CustomerController.groovy:45)
at grails.plugin.multitenant.core.servlet.CurrentTenantServletFilter.doFilter(CurrentTenantServletFilter.java:53)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
我在一個損失,因爲ZIPCODE列不是長在域類。任何指導將不勝感激。
編輯: 每個請求這裏是由遷移插件生成的變化:
changeSet(author: "user (generated)", id: "1363806498118-1") {
dropColumn(tableName: "admission", columnName: "pen")
addColumn(tableName: "admission") {
column(name:"pen_id", type:"bigint")
}
}
changeSet(author: "user (generated)", id: "1363806498118-2") {
addColumn(tableName: "customer") {
column(name: "billzipcode", type: "varchar(50)") {
constraints(nullable: "false")
}
}
}
changeSet(author: "user (generated)", id: "1363806498118-3") {
addColumn(tableName: "customer") {
column(name: "shipzipcode", type: "varchar(50)") {
constraints(nullable: "false")
}
}
}
changeSet(author: "user (generated)", id: "1363806498118-4") {
addColumn(tableName: "customer_costs") {
column(name: "subtotal", type: "float(19)") {
constraints(nullable: "false")
}
}
}
changeSet(author: "user (generated)", id: "1363806498118-5") {
addForeignKeyConstraint(baseColumnNames: "pen_id", baseTableName: "admission", constraintName: "FK1A21809D0C6EF15", deferrable: "false", initiallyDeferred: "false", referencedColumnNames: "id", referencedTableName: "pen", referencesUniqueColumn: "false")
}
changeSet(author: "user (generated)", id: "1363806498118-6") {
dropColumn(columnName: "zipcode", tableName: "customer")
}
你真的看過模式,以確保只有那兩個郵政編碼,它並沒有離開原來的列? – 2013-03-21 19:25:42
那麼,我不完全確定如何查看用於開發環境的數據庫的架構。數據源設置爲 - url =「jdbc:h2:db/dev; AUTO_SERVER = TRUE」 – TroyB 2013-03-21 19:46:50
發佈您的遷移。 – 2013-03-21 19:49:44