为什么更改域中的映射属性不会生成新的更改日志行?

Why does changing mapping properties in domain doesn't generate new changelog lines?

class Donation {

    BigDecimal amount

    static constraints = {
        amount min: BigDecimal.ZERO
    }

    static mapping = {
    }

}

添加后,域如下所示:

class Donation {

    BigDecimal amount       

    static constraints = {
        amount min: BigDecimal.ZERO
    }

    static mapping = {
        amount scale: 4
    }

}

进行更改后,我在 grails 控制台中 运行 dbm-gorm-diff 但它没有打印其他更改日志行。我想知道进行映射更改是否不会产生新的更改日志行。但是查看mysql数据库中"amount"的数据类型,显示为decimal(19,2)。我认为制作 scale 4 会将数据类型更改为 decimal(19, 4)。我感谢在这个困境中的任何帮助。谢谢!

虽然 db-migration 可以检测您的域中的更改,并且可以生成所需的更改日志来更新您的数据库架构。它不够智能,无法始终定位正确的更改。特别是在重命名 table/column 或更改列的数据类型时。在这种情况下,您需要进行手动迁移。

创建手动更新日志以使用 db-migration 更新架构:

databaseChangeLog = {

    changeSet(author: "sandeep (manual)", id: "20150901124635-01") {
        modifyDataType(columnName: "amount", newDataType: "decimal(19,4)", tableName: "donation")
    }
}

所以总是在生成更新日志后,验证它是否包含正确的更改。