when i send a form with a blank field i get an error SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'image' cannot be null. the only way to fix it that i found is to make a default value in the entity file:
* @ORM\Column(type="string", length=100)
*/
protected $image="";
and change the setter like this:
public function setImage($image){
if(!isset($image)) {
//its really empty but it works only in this way
}
else {
$this->image = $image;
}
I think that it is very starnge…
Is there any explanation for this? And is there another way to do it?
}
If the field
imageis not required, you can set it asnullableso Doctrine will know that and will set the column as being nullable.This way, constraint won’t be violated since the field can be null. To make a field nullable with Doctrine annotation, just add
nullable = truein theORM\Columndefinition like this:By default, all columns are
nullable=falseso they will throw a constaint validation exception when trying to persist a null value in it.Regards,
Matt