【发布时间】:2012-04-23 19:56:30
【问题描述】:
当我发送带有空白字段的表单时,我收到错误 SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'image' cannot be null。我发现修复它的唯一方法是在实体文件中设置一个默认值:
* @ORM\Column(type="string", length=100)
*/
protected $image="";
并像这样更改设置器:
public function setImage($image){
if(!isset($image)) {
//its really empty but it works only in this way
}
else {
$this->image = $image;
}
我觉得这很奇怪... 对此有什么解释吗?还有另一种方法吗? }
【问题讨论】:
-
属性
image是否是必需的?如果没有,你可以用这个定义代替@ORM\Column(type="string", length=100, nullable=true)。 -
这不是必需的。我提出了您的建议,并更新了架构,并且确实有效。谢谢!
-
我会把它作为一个答案,所以你可以接受它。
标签: forms symfony doctrine-orm