Grails 2.2.4:在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"
}

最新更新