【发布时间】:2011-05-09 20:15:09
【问题描述】:
我有一个域类,其中包含一个字符串字段,我将其更改为可为空。在 DataSource.groovy 中,我将模式设置为“更新”。有什么方法可以让 grails 在不更改为“create”或“create-drop”的情况下更改 MySql。我需要MySql中的数据。
后续问题:我可以使用“ALTER TABLE myProject_my_domain_class MODIFY the_string varchar(20) NULL;”行手动进行此更改这是可接受的做法吗?我也对链接到另一个域类的字段有同样的问题:
class myDomainClass {
MyOtherDomainClass otherThing
}
改成
class myDomainClass {
MyOtherDomainClass otherThing
static constraints = {
otherThing(nullable:true)
}
}
如果手动 SQL ALTER 是唯一的方法,那么编写 SQL 命令以便保留域类之间的 Key 索引的正确方法是什么?
【问题讨论】:
-
看来如果我只是做“ALTER TABLE myProejct_my_domain_class MODIFY other_thing_id bigint(20) NULL;”什么都没有。仍然想知道我是否使用了 Datasource.groovy 错误或其他一些 n00bsauce 答案。
标签: sql grails null nullable alter-table