在域 class 中使用 'Boolean' 变量,未创建 table

Use 'Boolean' variable in domain class, table not created

我想在具有 MySQL 数据库的 Grails 中的域 class 中使用布尔属性。但是,当我 运行 这个应用程序时,这个 table 没有创建,也没有任何错误消息。但是当我删除这个属性read时,这个table就创建成功了。

域class:

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
    }
}

我猜你遇到这个问题是因为 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'
    }
}