Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Impossible to load fixtures in Symfony2 "Could not find any fixtures to load"

I desperately try to load Doctrine fixtures into my DB. When I call the global cli load function, nothing looks bad at the beginning:

> purging database
> loading [1] namespace_of_my_first_fixture_file
> loading [2] namespace_of_my_second_fixture_file
...

But it fails in the middle of the process when it tries to re-use an object from a previous loaded fixtures (wrong index):

[ErrorException]                                                                                                                                                          
Notice: Undefined index: my_object_index in /Users/Swop/project/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php line 145

I look at the DB and nothing is inserted, in any tables. If I try to load only the first fixture (which seems to be loaded according to the above paste), I've got an error:

[InvalidArgumentException]                                          
Could not find any fixtures to load in:                             

- src/MyOrg/MyBundleBundle/DataFixtures/ORM/MyFirstFixtureFileData.php

By the way, I just run that on my MacOS X (Mountain Lion) with a self-compiled PHP 5.4 instance.

The fixtures data loading works well on my Linux box.

like image 255
Swop Avatar asked Oct 16 '12 20:10

Swop


2 Answers

I could not find a good example in the docs and finally found that this works. Just use the folder location and do not specify the fixture file.

doctrine:fixtures:load --fixtures=src/MyOrg/MyBundleBundle/DataFixtures/ORM --append
like image 83
George Avatar answered Sep 28 '22 03:09

George


Take a look at the DoctrineFixturesBundle documentation.

Your data fixture classes need to implement OrderedFixtureInterface so they are loaded in a pre-set order.

You can then setup references with $this->addReference('ref-name', $variable) and refer to those references in another fixture with $this->getReference('ref-name').

My guess as to why it seemed to work on your linux box is because the fixures were loaded in a different order.

like image 26
lifo Avatar answered Sep 28 '22 02:09

lifo