使用grails 2.2.5
& mySql
&此SO question设置列database-migration:1.3.2
中提到的deleted nullable:true
不会将值更改为DB
首先我添加了已删除的属性Boolean deleted
而没有deleted nullable:true
,所以当我将应用程序启动到我的数据库中时,我有Null:非(这是否法文)
然后我添加了deleted nullable:true
但是当我重新运行应用时没有任何变化,我仍然有Null : Non
(图片的最后一行)
我是否必须手动更改?
域名
class Comment {
Date dateCreated
Boolean deleted
String comment;
Boolean rootComment;
int vote;
static belongsTo = [contributor: Contributor, discussion: Discussion]
static hasOne = [project: Project]
static mapping = {
autoTimestamp true
deleted defaultValue: "0"
deleted nullable:true
}
}
请注意,在Datasource.groovy中,我有dbCreate = "update"
dataSource {
pooled = true
dbCreate = "update" // UPDATE
url = "jdbc:mysql://localhost:3306/soundsharedb"
driverClassName = "com.mysql.jdbc.Driver"
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
username = "xxx"
password = "xxx"
logSql = false
properties {
stOnBorrow = true
testWhileIdle = true
testOnReturn = true
validationQuery = 'SELECT 1'
}
}
答案 0 :(得分:1)
最好的办法是使用数据库迁移来更改该列的可空标志。我们对所有数据库操作使用迁移 - 创建/修改/删除表,列,索引,整个批次。
对于您要实施的更改,离散步骤可能类似于:
databaseChangeLog = {
changeSet(author: "You", id: "some unique ID") {
dropNotNullConstraint(columnDataType: "bit", columnName: "deleted", tableName: "comment")
}
}
阅读数据库迁移插件,了解如何生成/编写迁移,并将其用于程序化数据库更改。