doctrine / data-fixtures

Doctrine2 ORM Data Fixtures Extensions
http://www.doctrine-project.org
MIT License
2.78k stars 224 forks source link

Foreign key constraints - Postgres #246

Closed jbenezech closed 8 years ago

jbenezech commented 8 years ago

I have seen some fix and workarounds to solve the foreign key constraint problem with mysql but am using postgres and haven't found any easy way to bypass this.

My current workaround kind of works but make the test so slow they become unusable.

protected function fixturesLoad()
{
    $tool = new \Doctrine\ORM\Tools\SchemaTool(
         $this->getContainer()->get('doctrine')->getManager()
    );
    $tool->dropDatabase();
    $tool->createSchema($this->getContainer()->get('doctrine')->getManager()->getMetadataFactory()->getAllMetadata());

    return $this->loadFixtures(
mikeSimonson commented 8 years ago

@jbenezech What issue are you referencing ?

jbenezech commented 8 years ago

I think there are several pointing to the same problem: when there is a relationship between 2 entities as described below, when loading the fixtures and deleting the data, foreign key constraints are violated.

/**
* HarvestAnnouncement
* @ORM\Entity(repositoryClass="CRTP\HarvestBundle\Repository\HarvestAnnouncementRepository")
*/
class HarvestAnnouncement

    /**
    * @ORM\ManyToOne(targetEntity="CRTP\ProductBundle\Entity\SeedQuality")
    * @ORM\JoinColumn(name="seed_quality_id", referencedColumnName="id", nullable=false, onDelete="restrict")
    **/
    private $seedQuality;

This one for example, proposes a fix for mysql: https://github.com/doctrine/data-fixtures/issues/113

devantoine commented 8 years ago

I was about to open an issue for this exact same bug. It happens since the 1.2.0, and it is probably caused by this commit: https://github.com/doctrine/data-fixtures/pull/222

Currently I'm setting the version to 1.1.1 to avoid this bug.

mikeSimonson commented 8 years ago

@devantoine Can you check if you still have that issue with dev-master ? It should be fixed now. I f you confirm the fix then I will release 1.2.1

Thanks

devantoine commented 8 years ago

@mikeSimonson Yes, it's fixed! Thanks!

mikeSimonson commented 8 years ago

Done https://github.com/doctrine/data-fixtures/releases/tag/v1.2.2