我按照我在网上找到的许多地方的说明,对于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"
}