教义在MySQL中不生成跨数据库外键约束 [英] Doctrine not generating cross-database foreign key constraints in MySQL
问题描述
我有两个表db1.Contact和db2.Recipient.每个收件人都应该是一个联系人,因此我在db1.Contact.ContactID字段的两个表之间设置了一个外键.
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.
我在Recipient.php中用以下注释表示这一点:
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;
为此,我不需要在Contact.php中使用任何代码.
I shouldn't need any code in the Contact.php for this.
当我生成数据库时(使用主义orm:schema-tool:create --dump-sql),我可以看到创建了Recipient.ContactID字段并为其指定了索引.但是,不会生成查询并执行任何查询来创建外键约束.因此,很明显,我没有收到任何错误,但从未生成约束.
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.
这篇关于教义在MySQL中不生成跨数据库外键约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!