Reputation: 81
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.
Upvotes: 5
Views: 8076
Reputation: 968
I ran into the same problem when upgrading doctrine/doctrine-fixtures-bundle
This helped me out:
The automatic loading of fixtures in a directory (e.g. AppBundle\DataFixtures\ORM) was removed. Instead, register your fixture classes as services and tag then with doctrine.fixture.orm.
Source:https://github.com/doctrine/DoctrineFixturesBundle/blob/master/UPGRADE.md
Upvotes: 1
Reputation: 1630
Just run into this aswell. My fixtures where working on my local windows environment, but failed in my linux production environment.
My problem was case sensitivity (as it is so often in windows-linux).
I named the data fixtures directory
Datafixtures
While the script looks for
DataFixtures
Spot the capital F in the second directory name, I didnt ;-)
I hope this saves someones time.
Upvotes: 1
Reputation: 1489
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
Upvotes: 4
Reputation: 2893
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.
Upvotes: 1