mysql - Grails 属性不能为 null 错误

标签 mysql grails grails-orm

我的 Grails 应用程序运行良好。如果我没记错的话,我所做的就是将一个域类的约束从 blank: true, nullable:true 更改为 blank:false ,可为空: false。现在,当我尝试创建该类的新实例时,我收到以下错误消息:

Property [contract] of class [class com.app.Request] cannot be null
Property [description] of class [class com.app.Request] cannot be null
Property [productline] of class [class com.app.Request] cannot be null
Property [requestType] of class [class com.app.Request] cannot be null
Property [subject] of class [class com.app.Request] cannot be null

我已经为所有这些属性提供了值。

我猜测 gorm 和数据库之间存在一些冲突。有人可以向我解释一下发生了什么事以及如何解决它。

最佳答案

我遇到了类似的问题,已将约束更新为非空,但我存储的数据对于非空字段有空值。在某些时候,Grails 尝试加载现有数据,但在验证步骤中失败。

尝试使用一些默认值更新数据库(我的意思是使用纯 SQL UPDATE SET x = 'temp' WHERE x IS NULL),使 grails clean 并重新启动您的应用程序。应该有帮助。

关于mysql - Grails 属性不能为 null 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10698305/

相关文章:

mysql - 使用Go-Gorp创建表无法设置列详细信息

json - 可以在 Grails 1.3.7 中漂亮地打印 JSON 吗?

grails - 命令对象绑定(bind)到域类

php - SQL 查询中的 DISTINCT 日期时间

php - 如何获取md5加密的密码

php - 使用 PHP 的动态表

Grails 将 sqltype "number"转换为 String

grails - Grails SubFlow不呈现其 View 页面并返回HTTP 404

javascript - 如何从 GSP View 迭代 Javascript 中的 Groovy 集合

go - 何时是使用 GORM 运行 Automigrate 的最佳时机