Search code examples
grailsgrails-ormgrails-2.2column-defaults

Grails 2.2.4: creating a column default value in MySQL 5.5


I followed the instructions that I found many places online for how, for a Grails 2.2.4 domain object property, to create a default value on its corresponding MySQL 5.5 column.

Unfortunately, the columns that are supposed to have a default value do not have a default value applied to their MySQL columns.

Below are the relevant extracts from my domain object code. Is anything wrong?:

class SelectOption {

    int minSelectCount = 0
    int maxSelectCount = 1

    static constraints = {
        minSelectCount nullable: false, min: 0, defaultValue: "0"
        maxSelectCount nullable: false, min: 1, defaultValue: "1"
    }
}

Solution

  • Try putting defaultValue in the mapping block instead of constraints block.

    static mapping = {
        minSelectCount defaultValue: "0"
        maxSelectCount defaultValue: "1"
    }