Symfony 4.1-两个EntityManager。迁移在第二个EntityManager上进行了两次

时间:2018-11-01 17:14:11

标签: symfony doctrine-orm

我已按照此页面上的指示进行操作: https://symfony.com/doc/current/doctrine/multiple_entity_managers.html

我的doctrine.yaml文件如下:

doctrine:
    dbal:
        default_connection: one
        connections:
            one:
                # configure these for your database server
                url: '%env(DATABASE_ONE_URL)%'
                driver: 'pdo_mysql'
                server_version: '5.7'
                charset: utf8mb4
            two:
                # configure these for your database server
                url: '%env(DATABASE_TWO_URL)%'
                driver: 'pdo_mysql'
                server_version: '5.7'
                charset: utf8mb4

    orm:
        default_entity_manager: one
        entity_managers:
            one:
                connection: one
                mappings:
                    One:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/One'
                        prefix: 'App\Entity\One'
                        alias: One
            two:
                connection: two
                mappings:
                    Two:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/Two'
                        prefix: 'App\Entity\Two'
                        alias: Two

我的Entity目录中有一个目录1和2,两个目录中都有一个简单的Entity类:

一个中的

<?php

namespace App\Entity\One;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="person")
 */
class Person
{
    /**
     * @var int
     *
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(type="string")
     */
    private $name;

    {Getters and setters ...}
}

两个中的帖子

<?php

namespace App\Entity\Two;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="post")
 */
class Post
{
    /**
     * @var int
     *
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(type="string")
     */
    private $title;


    {Getters and setters ...}
}

当我运行bin/console doctrine:migrations:diffbin/console doctrine:migrations:migrate时,人员已正确添加到一个数据库中。

当我运行bin/console doctrine:migrations:diff --em=twobin/console doctrine:migrations:migrate --em=two时,将执行此迁移和 One Person 迁移,而 Two >数据库同时具有 Person Page 表。

我似乎无法弄清楚我要怎么做

0 个答案:

没有答案