1

With Doctrine in Symfony2 there is a simple way to start a project with reverse-engineered Entities created from existing database schema. It is quite well documented here. There is not mentioned how to reverse-engineer data from a non-default database when using multiple databases (which is documented here).

I found the solution here, it works like this:

php app/console doctrine:mapping:convert --em="troller" --from-database yml ./src/NAMESPACE/NAMEBundle/Resources/config/doctrine/metadata/orm

However, I'm just getting the exception as if the second entity manager didn't exist. Even though I have config.yml according to docs.

[InvalidArgumentException]                            
Doctrine ORM Manager named "troller" does not exist.

Any ideas?

4

1 回答 1

3

您是否指定了entity manager带有“troller”的名称?

你可以用这样的代码片段来做到这一点(进入app/config/config.yml文件)

orm:
  default_entity_manager:   default
  entity_managers:
    default:
      connection:       default
      mappings:
        AcmeDemoBundle: ~
        AcmeStoreBundle: ~
    troller:
      connection:       troller
      mappings:
        YourTrollerBundle: ~

在此示例中,您定义了两个名为default和的实体管理器troller。默认实体管理器管理AcmeDemoBundle和中的实体AcmeStoreBundle,而troller实体管理器管理 中的实体YourTrollerBundle您还定义了两个连接,每个实体管理器一个。

强行定义一个新的连接和实体管理器,还不够:您还必须指定“连接参数”(如数据库名称、用户、密码、驱动程序等)

troller:
  driver:   "%database_driver2%"
  host:     "%database_host2%"
  port:     "%database_port2%"
  dbname:   "%database_name2%"
  user:     "%database_user2%"
  password: "%database_password2%"
  charset:  UTF8
于 2013-05-06T07:01:38.637 回答