title: How to fix migrations running on both databases when setting up multiple databases with symfony4 and doctrine
body: <p>I am trying to setup a second database for a symfony 4.2 project. Everything seems to working fine up until the point where I run migrations where all migrations execute on the given connection instead of only the migrations for the connection it was created.</p>
  
  <p>Following <a href="https://symfony.com/doc/current/doctrine/multiple_entity_managers.html" rel="nofollow noreferrer">symfony's own documentation</a>   about this, my doctrine.yaml looks like this:</p>
  
  <pre><code>doctrine:
      dbal:
          default_connection: default
          connections:
              default:
                  driver: 'pdo_mysql'
                  server_version: '5.7'
                  charset: utf8mb4
                  default_table_options:
                      charset: utf8mb4
                      collate: utf8mb4_unicode_ci
                  url: '%env(DATABASE_URL)%'
              logging:
                  driver: 'pdo_mysql'
                  server_version: '5.7'
                  charset: utf8mb4
                  default_table_options:
                      charset: utf8mb4
                      collate: utf8mb4_unicode_ci
                  url: '%env(DATABASE_URL_LOG)%'
      orm:
          auto_generate_proxy_classes: '%kernel.debug%'
          default_entity_manager: default
          entity_managers:
              default:
                  connection: default
                  naming_strategy: doctrine.orm.naming_strategy.underscore
                  auto_mapping: true
                  mappings:
                      App:
                          is_bundle: false
                          type: annotation
                          dir: '%kernel.project_dir%/src/Entity'
                          prefix: 'App\Entity'
                          alias: App
              logging:
                  connection: logging
                  naming_strategy: doctrine.orm.naming_strategy.underscore
                  auto_mapping: false
                  mappings:
                      Log:
                          is_bundle: false
                          type: annotation
                          dir: '%kernel.project_dir%/src/Log'
                          prefix: 'App\Log'
                          alias: Log
  </code></pre>
  
  <p>Now with this configuration I am able to run the migration commands with the --em=log/default parameter like this:</p>
  
  <pre><code>php bin/console doctrine:migrations:diff --em=log
  php bin/console doctrine:migrations:migrate --em=log
  </code></pre>
  
  <p>And you get the expected results: It only creates a new migration for a new entity I created at src/Log when I add --em=log.</p>
  
  <p>this is the new entity:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace App\Log;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * @ORM\Entity()
   */
  class LogItem
  {
      /**
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       * @ORM\Column(type="integer")
       */
      private $id;
  }
  
  </code></pre>
  
  <p>However, the migration is created in the default src/Migrations folder and as a result:</p>
  
  <p>1) this migration is also executed when I run <code>doctrine:migrations:migrate --em=default</code> (creating the table in the default database)</p>
  
  <p>2) the entire default schema is loaded into the log database when I run <code>doctrine:migrations:migrate --em=log</code></p>
  
  <p>So I think the solution would be to split the migration files between the to entity managers into different directories. But I have been spending hours and can't find the way to do this for symfony4. Also, since the symfony documentation mentions absolutely nothing about this I feel like maybe something is wrong in the way it is setup now.</p>
  
  <p>So can anyone tell me what I am doing wrong here? Or can (and if yes: how) do I split the migration files so it will only execute the migrations created for the given entity manager?</p>