Symfony 4 Using Wrong Namespace When Making Entity

I've run into this issue a few times actually, when using php bin/console make:entity it uses the wrong namespace for the ManagerRegistry in the repository.

This is what it put in there:

use Doctrine\Persistence\ManagerRegistry;

Which then gives the following error:

Cannot autowire service "App\Repository\PrivateCallBookingAvailabilityRepository": argument "$registry" of method "__construct()" has type "Doctrine\Persistence\Manage  
  rRegistry" but this class was not found.  

Looking at other repositories it doesn't always do this, the ones that work actually use:

use Doctrine\Common\Persistence\ManagerRegistry;

Any idea why it's doing that?

1 answer

  • answered 2021-01-25 20:10 greeflas

    You need to downgrade version of symfony/maker-bundle because Doctrine\Common\Persistence\ManagerRegistry was renamed to Doctrine\Persistence\ManagerRegistry in Doctrine and looks like your Doctrine version has old name of this class.

    Also as an option you can update Doctrine to newest version.

    More details you can find here