when I submit a form with an empty field, I get an error SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'image' cannot be null. the only way to fix this that I found is to make a default value in the entity file:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'image' cannot be null
* @ORM\Column(type="string", length=100) */ protected $image="";
and change the customizer as follows:
public function setImage($image){ if(!isset($image)) { //its really empty but it works only in this way } else { $this->image = $image; }
I think this is very strict ... Is there any explanation for this? And is there any other way to do this? }
If the field is imagenot required, you can set it as nullable, so Doctrine will recognize it and set the column to NULL.
image
nullable
, , . Doctrine, nullable = true ORM\Column :
nullable = true
ORM\Column
@ORM\Column(type="string", length=100, nullable=true)
nullable=false, .
nullable=false
,Matt
:
Symfony2 nulls
, , Symfony $image null $entity->setImage(null), $image.
$image
$entity->setImage(null)
public function setImage($image){ if(!isset($image)) { // $image is null, symfony was trying to set $this->image to null, prevent it } else { $this->image = $image; } }
( ?). , $this->image ( , )
$this->image
public function setImage($image){ if(isset($image)) { // $image not null, go ahead and use it $this->image = $image; } }
$this->image, null.
null