Search code examples
grailsdatabase-migration

How to change a not nullable column to nullable in a Grails migration?


I need to change the columns currently not nullable to nullable using grails migration plugin. The dbm-gorm-diff command is throwing exception so what changeSet should I write to the changelog.


Solution

  • class Student
    {
    String Name
    String LName
    String MName
    
    static constraints={
    
    Name(nullablel:false,required:true)
    Lname(nullable:false,required:true)
    Mname(nullable:true,required:false)   
    }
    
    }
    

    // by default if you dont specify nullable const it will always be nullable but assume we are going to generate migration scrip for this

    //inside your script let say change Mname to nullable

    databaseChangeLog = {
    
        changeSet(author: "developerName (generated)", id: "1369639981631-1") {
    dropNotNullConstraint(columnDataType: "varchar(255)", columnName: "Mname", tableName: "student") 
     } 
         }