mysql 跨库建立外键,教义在MySQL中不生成跨数据库外键约束

I have two tables, db1.Contact and db2.Recipient. Every recipient should be a contact so I have a foreign key set up between the two tables on the db1.Contact.ContactID field.

I represent this in Recipient.php with the following annotation:

/**

* @ORM\Id

* @ORM\ManyToOne(targetEntity="\db1\Contact")

* @ORM\JoinColumn(name="ContactID", referencedColumnName="ContactID")

**/

private $Contact;

I shouldn't need any code in the Contact.php for this.

When I generate the database (using doctrine orm:schema-tool:create --dump-sql) I can see that the Recipient.ContactID field is created and given an index. However, no query is generated and executed to create the foreign key constraint. So to be clear, I don't get any errors but the constraint is never generated.

How can I resolve this? Surely doctrine supports cross-database foreign keys? I've checked out the annotation documentation and looked to see if there are any options for the create tool but I can't see any way to turn this functionality on.

解决方案

I found a workaround for this that I explain here. Essentially, Doctrine strips cross-database foreign keys by default because not all database systems support it, but you can disable it by commenting out some code in the Doctrine library.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值