使用教义从 Symfony2 中的外部数据库导入表 [英] Importing tables from external database in Symfony2 with doctrine

查看:16
本文介绍了使用教义从 Symfony2 中的外部数据库导入表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有自己数据库的 Symfony2 项目,现在我想连接到另一个数据库(另一个项目),以便我可以修改一些表.

我在 config_dev.yml

中创建了新连接

原则:分贝:默认连接:默认连接:默认:驱动程序:pdo_mysql主机:本地主机数据库名称:数据库 1用户:根密码:BUV:驱动程序:pdo_mysql主机:本地主机数据库名称:数据库2用户:根密码:

我尝试使用以下命令导入架构:

$ php 应用程序/控制台原则:映射:import --em=buv MyBundle yml

<块引用>

[DoctrineDBALSchemaSchemaException]表old_table"上不存在索引"

但是database2中的一些表没有PK!并且完全导入不起作用.但是我只想导入两个表,所以我尝试了:

$ php 应用程序/控制台原则:mapping:import --em=buv --filter="tablename" MyBundle yml

但我遇到了同样的错误,似乎 --filter 不起作用.

控制台命令 doctrine:mapping:import 中的文档只说将实体名称放在过滤器选项中.但我还没有实体.

解决方案

如果我没听错,你想导入现有的数据库吗?

我做的是:

php 应用程序/控制台原则:映射:转换 xml ./src/App/MyBundle/Resources/config/doctrine/metadata/orm --from-database --force

然后进行选择性转换为注解:

php 应用程序/控制台原则:映射:导入 AppMyBundle 注释 --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

[DoctrineDBALSchemaSchemaException] 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆