在域类中使用“Boolean”变量,未创建表

问题描述 投票:1回答:1

我想在Grails的域类中使用带有MySQL数据库的布尔属性。但是,当我运行此应用程序时,不会创建此表,并且没有任何错误消息。但是,当我删除此属性read时,此表已成功创建。

域类:

class Message {

    Player author
    Player target
    String content
    boolean read

    static constraints = {
        target nullable: false
        author nullable: false
        content blank: false
    }

    static mapping = {
        read defaultValue: false
    }
}
grails gorm
1个回答
3
投票

我想你正面临这个问题,因为read是保留关键字according to MySQL documentation

READ(R)

您可以将变量名称read更改为其他名称,或者您可以使用mapping闭包将列名更改为其他名称,例如:

class Message {

    Player author
    Player target
    String content
    boolean read

    static constraints = {
        target nullable: false
        author nullable: false
        content blank: false
    }

    static mapping = {
        read defaultValue: false, column: 'is_read'
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.