Search code examples
javamysqlgrailsgrails-orm

What happens if I change name of a field in a grails domain?


I had a grails domain with a field named created Though now I've changed it to dateCreated. However, my database table still has the column named created so anytime I try to save a record grails complains saying Field 'created' doesn't have a default value even though I no longer have this field in my domain.

How does one get around this issue? Do I have to open my db and delete this column? In rails this is handled through migrations, what is the equivalent in grails?


Solution

  • If you just rename the domain field, you can specify column name in the mapping block, and not change it when you rename the related field. So, no DB changes will be needed at all.

    class MyDomain {
        Date dateCreated
        static mapping = {
            dateCreated column: 'created'
        }
    }