尝试连接两个数据库时出现Symfony错误

问题描述 投票:0回答:2

我正在尝试连接两个数据库但是当我制作一个php bin/console doctrine:schema:update --force它返回

没有要处理的元数据类。

这是config.yml中的doctrine配置

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
php symfony doctrine-orm
2个回答
1
投票

我在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: ~

希望它可以帮助别人!


0
投票

一旦有多个实体管理器,您必须为每个实体管理器运行一次命令:

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

我还会给实体经理提供描述性的名称,当你将它们注入不同的服务时,它会更加清晰。

© www.soinside.com 2019 - 2024. All rights reserved.