I'm trying to use phinx to add a couple of related tables. I created my migration:
<?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();
}
}
But when I run the migration I get an error message saying it can't add the foreign key constraint:
I've tried various permutations of this including creating the child table in a different migration file, removing the cascade, explicitly unsigning the primary key in the parent table. All of these give me the same error. There's something I'm not seeing.
I'm using php 7.3 and phinx version 0.12.1
Any ideas?