I'm trying to add foreign keys to a table using a Phinx migration. My intention is to create a table ('sales_order_attachment') and add two foreign keys. There's not too much Phinx documentation, so I haven't found an answer on the internet or through tinkering (yet). What am I doing wrong here? Both tables and keys the migration is pointing to exist.
Migration:
public function up()
{
$table = $this->table('sales_order_attachment', array('id' => 'sales_order_attachment_id'));
$table->addColumn('file_upload_id', 'integer')
->addForeignKey('file_upload_id', 'file_upload', 'id');
$table->addColumn('sales_order_id', 'integer')
->addForeignKey('sales_order_id', 'sales_order', 'id')
->save();
}
public function down()
{
$this->table('sales_order_attachment')->drop();
}
Error:
[PDOException]
SQLSTATE[HY000]: General error: 1005 Can't create table 'table.sales_order_attachment' (errno: 150)
Do your other two tables already exist?
Maybe you could also try creating the 'sales_order_attachment' table first then adding the foreign keys in a separate step.
Regards,
Rob