【问题标题】:Tell doctrine that a field can be null告诉学说一个字段可以为空
【发布时间】:2016-02-10 22:01:24
【问题描述】:

我必须在学说实体的注释中输入什么。

其实是这样的……

/**
 * @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]: Integrity constraint violation: 1048 Column 'name' cannot be null

但是代码是什么?

【问题讨论】:

  • @ORM\Column(type="string", length=255, nullable=true)
  • 如果你在谷歌上搜索“空的学说”,那将是第一个结果,在该学说页面上,搜索“空”

标签: php doctrine entity symfony


【解决方案1】:

true在COLUMN属性中定义属性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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-11
    • 2018-08-06
    • 2020-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-03
    相关资源
    最近更新 更多