Php 加载夹具symfony2上的错误

Php 加载夹具symfony2上的错误,php,symfony,doctrine-orm,doctrine,Php,Symfony,Doctrine Orm,Doctrine,当我运行symfony命令加载装置时 我有个错误 SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'topic_id' cannot be null 可能是因为表标记中的列topic_id与表topic列topic_id有很多关系 我的固定装置 <?php class LoadTopicContentData extends AbstractFixture implements OrderedFixtureInt

当我运行symfony命令加载装置时

我有个错误

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'topic_id' cannot be null 
可能是因为表标记中的列topic_id与表topic列topic_id有很多关系

我的固定装置

<?php
class LoadTopicContentData extends AbstractFixture implements OrderedFixtureInterface
{
    public function getOrder()
    {
        return 1; // the order in which fixtures will be loaded
    }

    public function load(ObjectManager $manager)
    {
        $contentTopic1 = new TopicContent();
        $contentTopic1->setTopicId(1);



        $manager->flush();
    }


}

在调用flush之前必须保留对象(有关详细信息,请阅读条令文档)

我找到了解决办法。 必须在加载夹具之前添加合并引用

$contentTopic1->setTopic( $manager->merge($this->getReference('topic1')));


在主装置中,您必须与来自的addReference()共享对象。在数据库中插入数据时不使用persist()?
public function load(ObjectManager $manager)
{
    $contentTopic1 = new TopicContent();
    $contentTopic1->setTopicId(1);
    $manager->persist($contentTopic1);
    $manager->flush();
}
$contentTopic1->setTopic( $manager->merge($this->getReference('topic1')));
$this->addReference('topic1', $topic1);