Column type in grails not working

馋奶兔 提交于 2019-12-25 08:49:49

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!