vebbo
vebbo

Reputation: 270

Symfony2 & Doctrine - column is not inserted

I'm stuck with with strange error

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

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

I'm inserting value to non-nullable column 'typeId'. It is set in $request->get('typeId'), var_dump shows it is set in my entity, but inserting generates sql error

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 

value for typeId is set as null. But why? What am I missing?

Upvotes: 0

Views: 628

Answers (1)

Dos
Dos

Reputation: 861

You must to add nullable=true.

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

private $typeId;

Then run: php app/console doctrine:schema:update --force

Upvotes: 1

Related Questions