告诉一个字段可以为null的原则 [英] Tell doctrine that a field can be null

查看:117
本文介绍了告诉一个字段可以为null的原则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



其实就是这样...

  / ** 
* @ ORM\Column(type =string,length = 255)
*
* @ Assert\\ \\ Length(
* min = 3,
* max = 255,
* minMessage =名称太短,
* maxMessage =名称太长。,
* groups = {注册,个人资料}
*)
* /
protected $ name;

我必须告诉学说,像 canBeNull = true 。其他的我总是得到这个错误 SQLSTATE [23000]:完整性约束违反:1048列'名称'不能为空



但是代码如何?

解决方案

在COLUMN属性中定义可空



示例:

  / ** 
* @ ORM\Column(type =string,length = 255,nullable = true)
*
* @ Assert\Length(
* min =
* max = 255,
* minMessage =名称太短,
* maxMessage =名称太长,
* groups = {注册,个人资料}
*)
* /
protected $ name;


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?

解决方案

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;

这篇关于告诉一个字段可以为null的原则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆