Doctrine外键约束本地表为空

问题描述

使用 Doctrine DBAL v2.10.2 及其 Schema Manager,我需要获取外键约束的详细信息:

  • 本地表名
  • 外表名
  • 本地和国外专栏

除了本地表名 Doctrine\DBAL\Schema\ForeignKeyConstraint 外,所有内容都在 null 对象中设置。我怎样才能得到它?


如何复制
我有一个带有 referenced 主键列的 pk 表和一个带有 referencing 列引用 fkreferenced.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 (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...