In grails need to change a field in a domain class to nullable after I have already gone to production
I have a domain class with a string field that I am changing to nullable. In DataSource.groovy I have the mode set to "update." Is there any way to make grails alter the MySql without changing to "create" or "create-drop." I need the data in the MySql.
Follow up question: I can do this change by hand with the line "ALTER TABLE myProject_my_domain_class MODIFY the_string varchar(20) NULL;" Is this acceptable practice? Also I have the same problem with a field linking to another domain class:
class myDomainClass {
MyOtherDomainClass otherThing
}
changing to
class myDomainClass {
MyOtherDomainClass otherThing
static constraints = {
otherThing(nullable:true)
}
}
If the manual SQL ALTER is the only way, what is the correct way to write the SQL command so that I pre开发者_如何学JAVAserve the Key index between domain classes?
Have you tried the Database Migration Plugin?
http://www.grails.org/plugin/database-migration
The process of using it is a bit more manual than just setting dbCreate="update", but it gives you much greater control, and it picks up on changes like making a column nullable. In addition, you can check even your small schema changes into your version control system, so you have a record of the changes that you make.
精彩评论