Handling multiple database connections in Symfony 5.4 with Doctrine causing 'Connection not found' error
Does anyone know how to I'm trying to implement I've been banging my head against this for hours. I'm currently working on a Symfony 5.4 application that needs to connect to two different databases using Doctrine. I set up the `doctrine.yaml` configuration as follows: ```yaml doctrine: dbal: default_connection: default connections: default: driver: 'pdo_mysql' host: '%env(DB_HOST)%' dbname: '%env(DB_NAME)%' user: '%env(DB_USER)%' password: '%env(DB_PASSWORD)%' secondary: driver: 'pdo_mysql' host: '%env(SECOND_DB_HOST)%' dbname: '%env(SECOND_DB_NAME)%' user: '%env(SECOND_DB_USER)%' password: '%env(SECOND_DB_PASSWORD)%' orm: default_entity_manager: default entity_managers: default: connection: default mappings: App: is_bundle: false type: annotation dir: '%kernel.project_dir%/src/Entity' prefix: 'App\Entity' alias: App secondary: connection: secondary mappings: Secondary: is_bundle: false type: annotation dir: '%kernel.project_dir%/src/Entity/Secondary' prefix: 'App\Entity\Secondary' alias: Secondary ``` After configuring my entities to be mapped correctly to their respective database, I'm trying to retrieve data using the secondary connection. However, I'm encountering an error that states "Connection 'secondary' not found" when I attempt to run my repository queries for entities mapped under the `Secondary` entity manager. I've verified that the entity classes are in the correct folder and that the namespace is correct as well. Hereβs how Iβm trying to retrieve entities from the secondary database: ```php $entityManager = $this->getDoctrine()->getManager('secondary'); $repo = $entityManager->getRepository(SecondaryEntity::class); $result = $repo->findAll(); ``` I've also checked for typos in the connection names in the configuration file and ensured that both connection settings are being loaded correctly from the `.env` file. Any guidance on what I might be missing or how to troubleshoot this would be greatly appreciated! Am I missing something obvious? The project is a service built with Php. Am I approaching this the right way? Could this be a known issue?