我的 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/