我想将新字段添加到域类,以便它更新生成的表的属性集。我有这样的 Realm 类,
Class Book {
String name
static constraints = {
name nullable:false
}
String toString() {
return name
}
}
生成的GORM包括名称以及ID和版本。现在,我想将ISBN添加到Book域类,如下所示
Class Book {
String name
String ISBN
static constraints = {
name nullable:false
ISBN nullable:true
}
String toString() {
return name
}
}
我不想在
create-drop
中使用DataSource.groovy
,因为它会删除我以前的所有数据。我的DataSource.groovy
看起来像这样, dataSource {
dbCreate = "update"
url = "jdbc:jtds:sqlserver://localhost:1433/databaseName"
username = "username"
password = "password"
}
我希望GORM将ISBN字段添加到书表中。但是它没有发生。我哪里错了?
我正在使用SQL Server 2008和Grails版本2.1.1
最佳答案
dataSource {
dbCreate = "update"
}
应该可以。它在不删除表的情况下更新您的数据库
关于sql-server - 在Grails中更新域类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24286684/