问题
I have a domain class with few fields. The application was running and then I had to add 2 more fields to the domain class which were marked as nullable:
class SomeDomain{
// Fields from beginning
.............
// Two fields added afterwards
String fieldA
String fieldB
static constraints = {
// Constraints on initial fields
...............
// Constraints on fields added afterwards
fieldA(nullable: true)
fieldB(nullable: true)
}
}
But when I run this, then I see the fields added to mysql table. But they don't have the nullable constraint. So its not allowing nulls in those fields. What could be the reason and is there any way to solve this. Obviously I can edit the mysql tables directly to add the Nullable property to those two fields. However I want to know why it create the two fields in the table, but failed to add the null constraint(so that in future I can avoid such errors).
I am using Grails 2.2.1.
来源:https://stackoverflow.com/questions/31178945/grails-nullabletrue-not-working-after-modifying-domain-class