当我发送一个空白字段的表单我得到一个错误SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'image' cannot be null
。要解决这个问题,我发现的唯一方法是使实体文件的默认值:symfony2格式的空白字段奇怪
* @ORM\Column(type="string", length=100)
*/
protected $image="";
,改变这样的setter:
public function setImage($image){
if(!isset($image)) {
//its really empty but it works only in this way
}
else {
$this->image = $image;
}
我认为这是非常starnge .. 。 这有什么解释吗?还有另一种方法可以做到吗? }
属性'图像'是否需要?如果没有,你可以使用'@ORM \ Column(type =“string”,length = 100,nullable = true)'这个定义。 – Matt 2012-04-23 20:14:03
这不是必需的。我提出了你的建议,并更新了架构,确实有效。谢谢! – s976 2012-04-23 20:25:44
我要让它成为答案,所以你可以接受它。 – Matt 2012-04-23 20:27:19