Search code examples
grailsgrails-orm

Difference between blank and null constraints


What is the difference between the blank and null constraints ?

I have the following class

class Task {

    String title
    String notes
    TekUser assignedTo
    Date dueDate
    TekEvent event

    static constraints = {
        title blank:false
        notes blank: true , maxSize: 5000
        assignedTo nullable:true
        dueDate nullable:true
    }

    static belongsTo = TekEvent
}

and the mysql table created has the notes set to not null even though I specified notes blank : true

What effect does blank : true have ?


Solution

    • blank:true means the field accepts an empty string or one composed only by spaces as valid values. Eg: "", " "
    • nullable:true means the field accepts null as valid value

    They can be used together. Eg:

    title blank:false, nullable: true