2011-11-19 64 views
1

我在3个教义实体:SQLSTATE [23000]同时加入3个实体学说2和Symfony的2

一切工作顺利,直到我尝试添加任何 “答案”,然后我得到一个PDOException:

[PDOException] 
SQLSTATE[23000]: 
Integrity constraint violation: 
1452 Cannot add or update a child row: 
a foreign key constraint fails 
(`ankieter`.`answer`, CONSTRAINT `FK_DD714F131E27F6BF` FOREIGN KEY (`question_id`) REFERENCES `Question` (`id`)) 

Fixture code for testing

The error I get

编辑: 当我出口我的数据库结构与PhpMyAdmin,删除关于外键的信息和导入结构,一切运作良好(我我能够将数据添加到“答案”表)。 外键有什么问题?

回答

0

我认为你应该尝试拨打flush()创建每个问题。

0

尝试增加cascade={"persist"}到你的答案清晰的问题实体

@ORM\OneToMany(targetEntity="Answer", mappedBy="question", cascade={"persist"}) 

以及在答实体您的问题清晰

@ORM\ManyToOne(targetEntity="Question", inversedBy="answers", cascade={"persist"}) 

现在的教义应该能够坚持所有条目正确的顺序。