0

我有一个针对客户的域类。我最近不得不更改为域类,因为我们正在收集帐单地址和送货地址,但只记录了一个邮政编码值。所以我想一个简单的解决方法。将 zipcode 更改为 billzipcode,然后为 shipzipcode 创建一个新字段。我运行 dbm-gorm-diff 来创建更改日志,然后运行 ​​dbm-update 来执行我所做的更改。到目前为止,一切都很顺利。但随后我去调试应用程序以查看对数据源的更改是否正常。但是,现在当我尝试保存新的客户记录时,会出现以下错误:

    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")
}
4

1 回答 1

1

如果您注意到您的变更集,则 billzipcode 的条目实际上是添加一个新列,而不是重命名 zipcode 列。因此,您仍然必须管理数据迁移。这样的事情应该适用于你的情况:

changeSet(author: 'user (generated)', id: '1363806498118-4') {
    comment { 'Renaming zipcode to billzipcode' }
    renameColumn(tableName: 'customer_costs', oldColumnName: 'zipcode', newColumnName: 'billzipcode', columnDataType: 'varchar(50)')
}

这是一个相关问题,@Burt 接受的答案指向链接。

于 2013-03-22T06:20:35.753 回答