Symfony2& Doctrine - 未插入列

时间:2014-10-19 14:35:40

标签: php symfony doctrine-orm

我一直困扰着奇怪的错误

$thread->setTypeId($request->get('typeId'));
$thread->setStatusId(ThreadStatus::DRAFT);
$thread->setDateCreated(new \DateTime('now'));

var_dump($thread);
$this->em->persist($thread);
$this->em->flush();

我将值插入不可为空的列' typeId'。它设置在$ request-> get(' typeId')中,var_dump显示它是在我的实体中设置的,但是插入会生成sql错误

INSERT INTO threads (typeId, statusId, authorId, dateCreated, ...) VALUES (?, ?, ?, ?, ...)' with params [null, 1, 1, "2014-10-19 16:26:22", ...]
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'typeId' cannot be null 
typeId的

值设置为null。但为什么?我错过了什么?

1 个答案:

答案 0 :(得分:1)

您必须添加nullable=true

/**
 * @ORM\Column(name="typeId", type="integer", nullable=true)
 */

private $typeId;

然后运行:php app / console doctrine:schema:update --force