问题
This is my model.
class Review {
String review
Date date
int numberOfComments
String status
static belongsTo = [game:Game, user:User]
static hasMany=[comment:Comment]
static mapping ={
numberOfComments defaultValue: "0"
review type: 'text'
}
static constraints = {
}
when I inputted 400 character text it generated this error
I don't know why the review type: 'text' is not working. can someone help?
回答1:
In fact grails GORM sometimes have problems with updating column types, especially if they contain any data. Try to delete selected column/table in database and restart application.
Ensure also that you have changed in conf/DataSource.groovy
dbCreate = "update"
to
dbCreate = "create-drop"
Edited: Firstly I didn't notice that you are using h2 db. Please check out this answer for text type in h2 database.
回答2:
Maybe you can use an sqlType instead like
class Email {
String body
static mapping = {
body sqlType: "longtext"
}
回答3:
you can make it a blob
type
static mapping = {
review (type:’blob’)
}
Note type
is default properties for Grails 2.0, if you use newer version of grails you should use sqlType
.
Check it here: http://grails.github.io/grails-doc/latest/ref/Database%20Mapping/column.html
来源:https://stackoverflow.com/questions/34218991/column-type-in-grails-not-working