[英]Updating domain class in grails
I want to add new fields to a domain class so that it updates the generated table's attributes set. 我想将新字段添加到域类,以便它更新生成的表的属性集。 I have a domain class like this,, 我有这样的领域类,
Class Book {
String name
static constraints = {
name nullable:false
}
String toString() {
return name
}
}
The GORM generated includes name along with id and version. 生成的GORM包括名称以及ID和版本。 Now I want to add ISBN to Book domain class as following 现在,我想将ISBN添加到Book域类,如下所示
Class Book {
String name
String ISBN
static constraints = {
name nullable:false
ISBN nullable:true
}
String toString() {
return name
}
}
I don't want to use create-drop
in DataSource.groovy
because it will delete all my previous data. 我不想在DataSource.groovy
使用create-drop
,因为它将删除我以前的所有数据。 My DataSource.groovy
looks like this,, 我的DataSource.groovy
看起来像这样,
dataSource {
dbCreate = "update"
url = "jdbc:jtds:sqlserver://localhost:1433/databaseName"
username = "username"
password = "password"
}
I want GORM to add ISBN field to book table. 我希望GORM将ISBN字段添加到书表中。 But its not happening. 但是它没有发生。 Where am I wrong ? 我哪里错了?
I am using sql server 2008 and grails version 2.1.1 我正在使用SQL Server 2008和Grails版本2.1.1
dataSource {
dbCreate = "update"
}
should do the trick. 应该可以。 It updates you db without dropping the tables 它更新您的数据库,而无需删除表
you will need to crate this field in sql server by hand it use to be a easy task in sqlserver because all its tools, and you should take a look to grails database migration plugin documentation. 您将需要手工在sql server中创建该字段,因为在该字段中使用了所有工具,因此在sqlserver中使用该字段很容易,因此您应该查看一下graging数据库迁移插件文档。 It should be already installed in your grails version 它应该已经安装在您的grails版本中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.