Reputation: 862
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. Now I want to add ISBN to Book domain class as following
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. My DataSource.groovy
looks like this,,
dataSource {
dbCreate = "update"
url = "jdbc:jtds:sqlserver://localhost:1433/databaseName"
username = "username"
password = "password"
}
I want GORM to add ISBN field to book table. But its not happening. Where am I wrong ?
I am using sql server 2008 and grails version 2.1.1
Upvotes: 0
Views: 414
Reputation: 4998
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. It should be already installed in your grails version
Upvotes: 2
Reputation: 20707
dataSource {
dbCreate = "update"
}
should do the trick. It updates you db without dropping the tables
Upvotes: 3