我正在尝试连接两个数据库,但是当我进行php bin/console doctrine:schema:update --force
时,它返回
没有元数据类要处理。
这是config.yml
中的学说配置doctrine:
dbal:
default_connection: main
connections:
main:
driver: pdo_pgsql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: UTF8
rupe:
driver: pdo_pgsql
host: '%database_host2%'
port: '%database_port2%'
dbname: '%database_name2%'
user: '%database_user2%'
password: '%database_password2%'
charset: UTF8
orm:
default_entity_manager: main
entity_managers:
main:
connection: main
mappings:
Main:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/AppBundle/Entity/Main'
prefix: 'AppBundle\Entity\Main'
alias: Main
login:
connection: main
mappings:
LoginBundle:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/LoginBundle/Entity'
prefix: 'LoginBundle\Entity'
alias: LoginBundle
rupe:
connection: rupe
mappings:
Rupe:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/AppBundle/Entity/Rupe'
prefix: 'AppBundle\Entity\Rupe'
alias: Rupe
我在Symfony 3.4版本上找到了一个解决方案
doctrine:
dbal:
default_connection: main
connections:
main:
driver: pdo_pgsql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: UTF8
rupe:
driver: pdo_pgsql
host: '%database_host2%'
port: '%database_port2%'
dbname: '%database_name2%'
user: '%database_user2%'
password: '%database_password2%'
charset: UTF8
orm:
default_entity_manager: main
entity_managers:
main:
connection: main
mappings:
AppBundle: ~
LoginBundle: ~
rupe:
connection: rupe
mappings:
RupeBundle: ~
希望它能帮助别人!
拥有多个实体经理后,每个实体管理器必须运行一次命令:
php bin/console doctrine:schema:update --force --em default
php bin/console doctrine:schema:update --force --em login
php bin/console doctrine:schema:update --force --em rupe
验证架构时也需要相同的情况。
我建议您在拥有多个连接名称后更改连接名称。
doctrine:
dbal:
default_connection: main
connections:
main:
driver: pdo_pgsql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: UTF8
rupe:
driver: pdo_pgsql
host: '%database_host2%'
port: '%database_port2%'
dbname: '%database_name2%'
user: '%database_user2%'
password: '%database_password2%'
charset: UTF8
我还将为实体经理提供描述性名称,当您将其注入不同的服务时,它将更加清晰。