I'm trying to write this migration using only up and down method, but I'm getting this error.
SQLSTATE[HY000]: General error: 1553 Cannot drop index 'transaction_id': needed in a foreign key constraint
<?php
use \Test\Migrations\Migration;
class ModifyTableChargeback extends Migration
{
public function up()
{
$table = $this->table('mod_chargeback');
$table->addColumn('client_id', 'integer', ['after' => 'id'])
->addIndex('client_id')
->addColumn('invoice_id', 'integer', ['after' => 'client_id'])
->addIndex('invoice_id')
->addColumn('transaction_id', 'integer', ['after' => 'invoice_id'])
->addColumn('date_paid', 'datetime', ['null' => true, 'after' => 'result'])
->addColumn('date', 'date', ['null' => true, 'after' => 'date_paid'])
->addColumn('reason', 'string', ['null' => true, 'after' => 'date'])
->addColumn('issuer_message', 'string', ['null' => true, 'after' => 'reason'])
->addForeignKey('transaction_id', 'mod_transactions', 'id'
->update();
}
public function down()
{
$this->table('mod_chargeback')
->removeIndex('client_id')
->removeIndex('invoice_id')
->removeColumn('client_id')
->removeColumn('invoice_id')
->removeColumn('transaction_id')
->removeColumn('date_paid')
->removeColumn('date')
->removeColumn('reason')
->removeColumn('issuer_message')
->dropForeignKey('transaction_id')
->update();
}
}
I tried to add the constraint in the $options parameter but without success The up method is working, but in the drop it doesn't remove the foreign key, I've tried to reorder the drop orders but without success too.