Php Symfony2&;原则-未插入列

Php Symfony2&;原则-未插入列,php,symfony,doctrine-orm,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(); 我正在向不可为空的列

我被奇怪的错误缠住了

$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\u 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应用程序/控制台原则:schema:update--force

typeId是否设置为自动增量?@hermannstepanentsamo no
/**ORM\Column(name=“typeId”,type=“integer”)*/private$typeId运行>>
php应用程序/控制台原则:模式:更新--force
以确保您的数据库与您的命名同步。@HermannStephaneNtsamo没有帮助,如果您转到数据库并
描述线程,同样的事情它是否将typeId显示为PK?此列不应为空,但我设法解决了此问题。我将
type
设置为引用表中的对象,而不是设置
typeId
。它现在可以正常工作了,您应该这样做:)。