I'm trying to drop a unique constraint and I keep running into a foreign key constraint issue:
Here's the original migration:
Schema::table('table', function (Blueprint $table) {
$table->bigInteger('other_table_id')->unsigned()->unique()->nullable();
$table->foreign('other_table_id')->references('id')->on('other_table')->onDelete('set null');
});
Fast forward to now, I'm trying to drop the UNIQUE constraint from the column on the table without affecting the foreign key.
Schema::table('table', function (Blueprint $table) {
$table->dropUnique('table_other_table_id_unique');
});
Here's the error I'm getting.
SQLSTATE[HY000]: General error: 1553 Cannot drop index 'table_other_table_id_unique': needed in a foreign key constraint
I've also tried using
Schema::table('table', function (Blueprint $table) {
$table->dropUnique(['other_table_id']);
});
But that didn't work either.
I even tried disabling the foreign key constraint while doing the migration:
Schema::disableForeignKeyConstraints(); // Disable constraint
Schema::table('table', function (Blueprint $table) {
$table->dropUnique(['other_table_id']);
});
Schema::enableForeignKeyConstraints(); // Reenable constraint
Nothing seems to work. What am I doing wrong?