I try to remove a column, which is a foreign key:
$table = $this->table('users');
$table->removeColumn('province_id');
$table->update();
Above gives DB error: The object 'users_province_id' is dependent on column 'province_id'. If I try to remove FK first:
$table = $this->table('users');
$table->removeIndex('province_id');
$table->removeColumn('province_id');
$table->update();
I get the same error. Using removeIndexByName:
$table = $this->table('users');
$table->removeIndexByName('users_province_id');
$table->removeColumn('province_id');
$table->update();
Also doesn't work. Thanks for any help.
Your code doesn't remove foreign key constraints, but only indexes and columns. To remove a foreign key constraint, you'd use the
dropForeignKey()method, something along the lines of this:See also