1

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"
    }
}
XDR
  • 4,070
  • 3
  • 30
  • 54

1 Answers1

5

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

static mapping = {
    minSelectCount defaultValue: "0"
    maxSelectCount defaultValue: "1"
}
cfrick
  • 35,203
  • 6
  • 56
  • 68
Abe
  • 8,623
  • 10
  • 50
  • 74