Symfony 3.4.0 Could not find any fixture services to load
This command looks for all services tagged with doctrine.fixture.orm
.
There is two ways to fix this problem.
First one: any class that implements
ORMFixtureInterface
will automatically be registered with this tag.
<?phpnamespace AppBundle\DataFixtures\ORM;use Doctrine\Bundle\FixturesBundle\ORMFixtureInterface;use Doctrine\Common\Persistence\ObjectManager;class LoadFixtures implements ORMFixtureInterface{ public function load(ObjectManager $manager) { #your code }}
Second one: You need manually tag
doctrine.fixture.orm
toDataFixtures
insevice.yml
configuration.
services: ... # makes classes in src/AppBundle/DataFixtures available to be used as services # and have a tag that allows actions to type-hint services AppBundle\DataFixtures\: resource: '../../src/AppBundle/DataFixtures' tags: ['doctrine.fixture.orm']
I tried @Alexander's solution but it's doesn't work for me.
I had resolved the same problem by adding the tag service to the class, Symfony doc on the services.yml
file bundle:
BlogBundle/Resources/config/services.yml
Services:...# Fixtures services BlogBundle\DataFixtures\ORM\PostFixture: tags: [doctrine.fixture.orm]...
My BlogBundle/DataFixtures/ORM/PostFixture.php
class :
...use Doctrine\Common\DataFixtures\FixtureInterface;use Doctrine\Common\Persistence\ObjectManager;...class PostFixture implements FixtureInterface{public function load(ObjectManager $manager) {...}}
Source Inspiration : Synfony doc -> Service container -> The autoconfigure Option
Hope it'll an alternative solution
Example for reusable bundle.
src/Acme/Bundle/UserBundle/DataFixtures/ORM/DataFixtures.php
<?php namespace Acme\Bundle\UserBundle\DataFixtures\ORM;use Doctrine\Bundle\FixturesBundle\Fixture;use Doctrine\Common\Persistence\ObjectManager;class DataFixtures extends Fixture{ /** * Load data fixtures with the passed EntityManager * * @param ObjectManager $manager */ public function load(ObjectManager $manager) { #your code }}
in app/config/services.yml
Acme\Bundle\UserBundle\DataFixtures\: resource: '../../src/Acme/Bundle/UserBundle/DataFixtures/'
append your fixtures data:
php bin/console doctrine:fixtures:load --append