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

时间:2018-09-12 11:16:07

标签: grails gorm

我想在带有MySQL数据库的Grails中的域类中使用布尔属性。但是,当我运行此应用程序时,不会创建此表,并且没有任何错误消息。但是,当我删除此属性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
    }
}

1 个答案:

答案 0 :(得分: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'
    }
}