我正在尝试使用 phinx 添加几个相关的表。我创建了我的迁移:
<?php
use Phinx\Migration\AbstractMigration;
class CreatesCognitiveMappingTables extends AbstractMigration
{
public function up()
{
$this->table("cognitive_mapping")
->changeColumn('id', 'biginteger', ['identity' => true])
->addColumn("user_id", "biginteger", ["signed" => false])
->addColumn("participant_id", "integer")
->addColumn("session_number", "integer")
->addColumn("date_time", "datetime")
->addColumn("image_file_link", "text")
->addColumn("time", "decimal", ["precision" => 10, "scale" => 5])
->addColumn("test_trial_complete", "boolean")
->addTimestamps()
->create();
$child = $this->table("cognitive_mapping_dragdrop_results");
$child
->changeColumn('id', 'biginteger', ['identity' => true])
->addColumn("cognitive_mapping_id", "biginteger", ["signed" => false])
->addColumn("box_number", "integer")
->addColumn("correct_answer", "text")
->addColumn("given_answer", "text")
->addColumn("accuracy", "boolean")
->addTimestamps()
->create();
$child
->addForeignKey("cognitive_mapping_id", "cognitive_mapping", "id", ["delete" => "CASCADE"])
->save();
}
public function down()
{
$this->table("cognitive_mapping_dragdrop_results")->drop()->save();
$this->table("cognitive_mapping")->drop()->save();
}
}
但是当我运行迁移时,我收到一条错误消息,说它无法添加外键约束:
我尝试了各种排列方式,包括在不同的迁移文件中创建子表、删除级联、显式取消对父表中的主键的签名。所有这些都给了我同样的错误。有些东西我没看到。
我正在使用 php 7.3 和 phinx 版本 0.12.1
有任何想法吗?