如何解决Doctrine外键约束本地表为空
使用 Doctrine DBAL v2.10.2 及其 Schema Manager,我需要获取外键约束的详细信息:
- 本地表名
- 外表名
- 本地和国外专栏
除了本地表名 Doctrine\DBAL\Schema\ForeignKeyConstraint
外,所有内容都在 null
对象中设置。我怎样才能得到它?
如何复制:
我有一个带有 referenced
主键列的 pk
表和一个带有 referencing
列引用 fk
的 referenced.pk
表。
这是我的调试脚本的主要部分:
$connection = DriverManager::getConnection([
'url' => 'MysqL://root:root@127.0.0.1:3306/fregata_source'
]);
$foreignKeys = $connection->getSchemaManager()->listTableForeignKeys('referencing');
var_dump($foreignKeys[0]);
输出:
object(Doctrine\DBAL\Schema\ForeignKeyConstraint)#10 (8) {
["_localTable":protected]=>
NULL
["_localColumnNames":protected]=>
array(1) {
["fk"]=>
object(Doctrine\DBAL\Schema\Identifier)#11 (3) {
["_name":protected]=>
string(2) "fk"
["_namespace":protected]=>
NULL
["_quoted":protected]=>
bool(false)
}
}
["_foreignTableName":protected]=>
object(Doctrine\DBAL\Schema\Identifier)#12 (3) {
["_name":protected]=>
string(10) "referenced"
["_namespace":protected]=>
NULL
["_quoted":protected]=>
bool(false)
}
["_foreignColumnNames":protected]=>
array(1) {
["pk"]=>
object(Doctrine\DBAL\Schema\Identifier)#13 (3) {
["_name":protected]=>
string(2) "pk"
["_namespace":protected]=>
NULL
["_quoted":protected]=>
bool(false)
}
}
["_options":protected]=>
array(2) {
["onDelete"]=>
NULL
["onUpdate"]=>
NULL
}
["_name":protected]=>
string(18) "referencing_ibfk_1"
["_namespace":protected]=>
NULL
["_quoted":protected]=>
bool(false)
}
您可以看到,我为 NULL
属性获得了 _localTable
,而我希望 referencing
表有一个标识符。我用 sqlite 数据库和 MysqL 数据库得到了相同的结果。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。