Symfony 2 and Multiple databases with config.yml settings

533 views Asked by At

I have a problem in Symfony 2.3 specifically, where I need to generate schema and update it, access tables in 2 differents databases. Both are in MySQL. How to Work with multiple Entity Managers and Connections doesn't fix to the scenario, even it's recommended in some articles around.

Errors:

[RuntimeException]
Bundle "XyzBundle" does not contain any mapped entities.

Commands:

  • doctrine:generate entities XyzBundle --no-backup
  • doctrine:schema:update --force --em=payment

#/app/config/config.yml

doctrine:
  #... connections (default, payment, etc.)
  orm:
    default_entity_manager: default
    auto_generate_proxy_classes: "%kernel.debug%"
    entity_managers:
        default:
            connection: default
            mappings:
                MyBundle: ~           
        payment:
            connection: payment
            mappings:
                ZkPaymentBundle: ~
1

There are 1 answers

0
Felix Aballi On

First, I found these excellent articles, where many configurations forms are mentioned.

Doctrine ORM

Install Gedmo Doctrine2 extensions in Symfony2

Even when the bundle isn't in 'vendor/' dir, it was necessary assume that was an external one.

#/app/config/config.yml

        payment:
            connection: payment
            mappings:
                XyzBundle:
                    type: annotation
                    prefix: Xyz\XyzBundle\Entity
                    dir: "%kernel.root_dir%/../src/Xyz/XyzBundle/Entity"

Commands

  • doctrine:generate:entities Xyz/XyzBundle/Entity --no-backup
  • doctrine:schema:update --force --em=payment

I hope it saves a lot of wasted time.