Doctrine not detecting schema changes with one entity manager and multiple databases(一个实体管理器和多个数据库未检测到模式更改的学说)
问题描述
使用 Symfony-2.1 和 Doctrine-2.3.我有多个数据库,需要进行跨数据库连接,所以我遵循了以下建议:
Using Symfony-2.1 and Doctrine-2.3. I have multiple databases and need to do cross-database joins so I followed the suggestions in:
- Doctrine2 和 Zend 框架中的多数据库连接
- 使用与多个实体经理的关系
并设置多个连接和一个实体管理器.这是app/config/config.yml:
and set up multiple connections and one entity manager. Here is app/config/config.yml:
doctrine:
dbal:
default_connection: db1
connections:
db1:
driver: pdo_mysql
host: 127.0.0.1
dbname: db1
db2:
driver: pdo_mysql
host: 127.0.0.1
dbname: db2
orm:
default_entity_manager: default
auto_generate_proxy_classes: %kernel.debug%
entity_managers:
default:
auto_mapping: true
mappings:
FirstBundle:
type: annotation
dir: Model
prefix: NoiseLabsFirstBundleModel
SecondBundle:
type: annotation
dir: Model
prefix: NoiseLabsSecondBundleModel
FirstBundle中的实体类:
namespace NoiseLabsFirstBundleModel;
/**
* @ORMEntity
* @ORMTable(name="db1.table1")
*/
class FirstEntity
{
/**
* @ORMId
* @ORMColumn(name="id", type="integer")
* @ORMGeneratedValue(strategy="AUTO")
*/
protected $id;
}
SecondBundle中的实体类:
namespace NoiseLabsSecondBundleModel;
/**
* @ORMEntity
* @ORMTable(name="db2.table2")
*/
class SecondEntity
{
/**
* @ORMId
* @ORMColumn(name="id", type="integer")
* @ORMGeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORMManyToOne(targetEntity="NoiseLabsFirstBundleModelFirstEntity")
* @ORMJoinColumn(name="firstId", referencedColumnName="id", onDelete="CASCADE")
*/
protected $first;
}
现在,问题是 app/console dictionary:schema:update --dump-sql 仅检测(默认连接)db1.tables 中的架构更改.如果我将默认连接设置为 db2 它只会输出与 db2.tables 相关的 sql.
Now, the problem is app/console doctrine:schema:update --dump-sql only detects schema changes in (default connection) db1.tables. If I set the default connection to db2 it will only output sql related to db2.tables.
我已经检查了 app/console dictionary:mapping:info 并且正在映射所有实体类.
I've checked with app/console doctrine:mapping:info and all entity classes are being mapped.
这是 Doctrine/Symfony 的限制还是我需要调整我的配置?谢谢.
Is this a limitation of Doctrine/Symfony or do I need to adjust my configuration? Thanks.
推荐答案
每个实体管理器只能有一个连接.将默认实体管理器一分为二.app/console dictionary:schema:update 采用可选参数 (em) 来指定正在使用的实体管理器.你必须运行它两次:
Each entity manager can have only one connection. Split the default entity manager into two. app/console doctrine:schema:update takes an optional argument (em) to specify the entity manager in use. You'd have to run it twice:
app/console doctrine:schema:update --dump-sql em="default"
app/console doctrine:schema:update --dump-sql em="my_second_em"
还有一篇短文(如何使用多个实体管理器和连接) 在值得一读的 Symfony2 食谱中.
There's also a short article (How to work with Multiple Entity Managers and Connections) in the Symfony2 cookbook that's worth reading.
这篇关于一个实体管理器和多个数据库未检测到模式更改的学说的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:一个实体管理器和多个数据库未检测到模式更改的学说
基础教程推荐
- Web 服务器如何处理请求? 2021-01-01
- php中的foreach复选框POST 2021-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- php中的PDF导出 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
