Tell doctrine that a field can be null

2019-03-05 16:03发布

What do I have to enter in the annotation of a doctrine entity.

Its actually like this...

/**
 * @ORM\Column(type="string", length=255)
 *
 * @Assert\Length(
 *     min=3,
 *     max=255,
 *     minMessage="The name is too short.",
 *     maxMessage="The name is too long.",
 *     groups={"Registration", "Profile"}
 * )
 */
protected $name;

I have to tell doctrine something like canBeNull=true. Otherwhise I always get this error SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null

But whats the code?

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-03-05 16:13

Define the attribute nullable in the COLUMN property with true.

Example:

/**
 * @ORM\Column(type="string", length=255, nullable=true)
 *
 * @Assert\Length(
 *     min=3,
 *     max=255,
 *     minMessage="The name is too short.",
 *     maxMessage="The name is too long.",
 *     groups={"Registration", "Profile"}
 * )
 */
protected $name;
查看更多
登录 后发表回答