我使用grails migration(liquibase)为表SCOMMENT
添加了2个新列SURL
和DB_SERVER
databaseChangeLog = {
changeSet(author: "syam (generated)", id: "changelog-2.3.6") {
addColumn(tableName:"DB_SERVER"){
column(name:"SCOMMENT", type:"VARCHAR2(255 CHAR)"){
constraints(nullable: "true")
}
}
addColumn(tableName:"DB_SERVER"){
column(name:"SURL", type:"VARCHAR2(255 CHAR)"){
constraints(nullable: "true")
}
}
}
}
最初我定义了SCOMMENT
和SURL
,长度为255个字符。在下一个版本中,我尝试使用modifyColumn
将字符长度增加到1024,如下所示
databaseChangeLog = {
changeSet(author: "syam (generated)", id: "changelog-2.3.7") {
// Increase maximum length of characters for scomment field in DbServer
modifyDataType(columnName:"SCOMMENT", tableName:"DB_SERVER", newDataType="VARCHAR2(1024 CHAR)")
//Increase the maximum length of characters for surl field in DbServer
modifyDataType(columnName:"SURL", tableName:"DB_SERVER", newDataType="VARCHAR2(1024 CHAR)")
}
}
当我尝试迁移时,出现以下错误
Error 2014-12-08 13:11:28,086 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: liquibase.exception.ValidationFailedException: Validation Failed:
2 changes have validation failures
newDataType is required, changelog-2.3.7.groovy::changelog-2.3.7::syam(generated)::(Checksum: 3:04f74b0209f64ad261e4a864fcc3c43c)
Message: liquibase.exception.ValidationFailedException: Validation Failed:
2 changes have validation failures
newDataType is required, changelog-2.3.7.groovy::changelog-2.3.7::syam (generated)::(Checksum: 3:04f74b0209f64ad261e4a864fcc3c43c)
Line | Method
->> 262 | run in java.util.concurrent.FutureTask
如何更改SCOMMENT
和SURL
的字符长度?
答案 0 :(得分:2)
错误是Liquibase错误,而不是数据库错误。 Liquibase没有看到newDataType属性,因此抛出了验证错误,但您正在设置它。我能够使用标准liquibase和xml或json运行类似的changeSet,因此它可能是grails DSL的问题。可能值得向他们提出问题。
你总是可以回到" sql"命令,如果grails解析有问题,也可以直接传递ALTER TABLE语句。
答案 1 :(得分:1)
我必须这样做,复制你的代码并得到同样的错误。我发现你有一个错字:你必须更换' ='用':' in" newDataType = ..."。然后,我没有错误的修复。
答案 2 :(得分:0)
您发布的示例有拼写错误。你有一个等号,你应该有一个冒号:
更改
modifyDataType(columnName:"SCOMMENT", tableName:"DB_SERVER", newDataType="VARCHAR2(1024 CHAR)")
要
modifyDataType(columnName:"SCOMMENT", tableName:"DB_SERVER", newDataType:"VARCHAR2(1024 CHAR)")
答案 3 :(得分:0)
根据您使用的数据库的sql方言,更改集语法会有所不同。 使用MySQL GORM:
databaseChangeLog = {
changeSet(author: "kujalpe (manual)", id: "1493972667393-1") {
comment{'BUG-1 Increase SCOMMENT column size in DB_SERVER table'}
modifyDataType(tableName: "DB_SERVER", columnName: "SCOMMENT", newDataType: "varchar(1024)")
}
}