从Symfony2的外部数据库导入表与原则 [英] Importing tables from external database in Symfony2 with doctrine
问题描述
我创建config_dev.yml中的新连接
doctrine:
dbal:
default_connection:default
连接:
默认值:
驱动程序:pdo_mysql
主机:localhost
dbname:database1
用户:root
密码:
buv:
驱动程序:pdo_mysql
主机:localhost
dbname:database2
用户:root
密码:
我尝试使用以下命令导入模式:
$ php app / console doctrine :mapping:import --em = buv MyBundle yml
[Doctrine\DBAL\Sc hema\SchemaException]
索引''不存在于表'old_table'
但是数据库2中的某些表没有PK!而且全部进口都不行。但是我只想导入两个表,所以我试过:
$ php app / console doctrine:mapping:import --em = buv --filter =tablenameMyBundle yml
但是我收到相同的错误,似乎--filter不工作。
控制台命令中的文档doctrine:mapping:import只表示将实体名称放在filter选项中。但是我还没有一个实体。
如果我正确地找到你想要导入现有的数据库? / p>
我所做的是:
php app / console doctrine:mapping :转换xml ./src/App/MyBundle/Resources/config/doctrine/metadata/orm --from-database --force
然后做一个选择性转换为注释:
php app / console doctrine:mapping:import AppMyBundle annotation --filter =users_table
如果您想要yml,请将注释更改为yml。
警告:当您导入注释或yml时,它将删除您当前的实体文件。
I have a Symfony2 project with its own database, and now I want to connect to another database (another project) so I can modify some tables.
I created the new connection in config_dev.yml
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
host: localhost
dbname: database1
user: root
password:
buv:
driver: pdo_mysql
host: localhost
dbname: database2
user: root
password:
I tried to import the schema with the following command:
$ php app/console doctrine:mapping:import --em=buv MyBundle yml
[Doctrine\DBAL\Schema\SchemaException] Index '' does not exist on table 'old_table'
But some of the tables in database2 have no PKs! And the full import dosn't work. But I only want to import two tables, so I tried:
$ php app/console doctrine:mapping:import --em=buv --filter="tablename" MyBundle yml
But I'm getting the same error, seems that --filter isn't working.
The documentation in the console command doctrine:mapping:import only says to put the entity name in the filter option. But I don't have an entity yet.
If I get you correctly, you want to import your existing database?
What I do is:
php app/console doctrine:mapping:convert xml ./src/App/MyBundle/Resources/config/doctrine/metadata/orm --from-database --force
Then do a selective convert to annotation:
php app/console doctrine:mapping:import AppMyBundle annotation --filter="users_table"
If you wanted to yml, change annotation to yml.
warning: when you import to annotation or yml, it will delete your current entity file.
这篇关于从Symfony2的外部数据库导入表与原则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!