我遇到了一个奇怪的错误
$thread->setTypeId($request->get('typeId'));
$thread->setStatusId(ThreadStatus::DRAFT);
$thread->setDateCreated(new 'DateTime('now'));
var_dump($thread);
$this->em->persist($thread);
$this->em->flush();
我正在将值插入到不可为null的列"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。但为什么呢?我错过了什么?
您必须添加nullable=true
。
/**
* @ORM'Column(name="typeId", type="integer", nullable=true)
*/
private $typeId;
然后运行:php-app/console原则:模式:更新-强制