Grails 2.2.4:在 MySQL 5.5 中创建列默认值

Grails 2.2.4: creating a column default value in MySQL 5.5

我按照我在网上找到的许多地方的说明进行操作,了解如何为 Grails 2.2.4 域对象 属性 在其对应的 MySQL 5.5 列上创建默认值。

不幸的是,应该有默认值的列没有应用到它们的 MySQL 列的默认值。

以下是我的域对象代码的相关摘录。有什么问题吗?:

class SelectOption {

    int minSelectCount = 0
    int maxSelectCount = 1

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

尝试将 defaultValue 放在 mapping 块而不是 constraints 块中。

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