Symfony 3.4.0 Could not find any fixture services to load

Alexander picture Alexander · Dec 3, 2017 · Viewed 16.7k times · Source

I am using Symfony 3.4.0, I try to load fixtures with:

php bin/console doctrine:fixtures:load

An error occurred while creating the data, what's wrong?

enter image description here

Answer

GuRu picture GuRu · Jan 1, 2018

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.

<?php

namespace 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 to DataFixtures in sevice.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']