Search code examples
phpmysqlsymfonydoctrine-ormdatabase-migration

Symfony Doctrine Migrations, how can I use multiple entity managers


Using Symfony 2.5 and Doctrine 2.2, I have several databases for an application I'm working on, let's call one "Main" and the other "Secondary". There are currently two entity managers configured. In one migration I want to create a table in "Secondary" but it only wants to create the table in "Main."

A migration can be ContainerAware, so I can get another EntityManager, but I have been unable to override the default one. Any able to help? Thanks in advance!


Solution

  • Just pass --em parameter when generating diff.

    Example:

    php app/console doctrine:migrations:diff --em=uac # will use uac entity manager
    php app/console doctrine:migrations:diff # will use the default entity manager
    

    To exclude custom tables from removal use:

    doctrine:
        dbal:
            schema_filter: ~^(?!t_)~
    

    as per this document, alternatively you can pass filter argument at the runtime:

    app/console doctrine:migrations:diff  --em=uac --filter-expression=/whatever/