Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 告诉条令一个字段可以为空_Php_Doctrine_Entity_Symfony - Fatal编程技术网

Php 告诉条令一个字段可以为空

Php 告诉条令一个字段可以为空,php,doctrine,entity,symfony,Php,Doctrine,Entity,Symfony,我必须在条令实体的注释中输入什么 其实是这样的 /** * @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"}

我必须在条令实体的注释中输入什么

其实是这样的

/**
 * @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;
我必须告诉你一些事情,比如
canBeNull=true
。否则,我总是会遇到此错误
SQLSTATE[23000]:完整性约束冲突:1048列“name”不能为null


但是代码是什么?

使用true在列属性中定义属性nullable

例如:

/**
 * @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;

使用true在列属性中定义属性nullable

例如:

/**
 * @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;

@ORM\Column(type=“string”,length=255,nullable=true)如果你用谷歌搜索“条令列null”,这将是第一个结果,在该条令页面上,搜索“null”@ORM\Column(type=“string”,length=255,nullable=true)如果你用谷歌搜索“条令列null”,这将是第一个结果,在该条令页面上,搜索“null”