我已按照此页面上的指示进行操作: 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:diff
和bin/console doctrine:migrations:migrate
时,人员已正确添加到一个数据库中。
当我运行bin/console doctrine:migrations:diff --em=two
和bin/console doctrine:migrations:migrate --em=two
时,将执行此迁移和 One 的 Person 迁移,而 Two >数据库同时具有 Person 和 Page 表。
我似乎无法弄清楚我要怎么做