I have created unique index:
$table->unique(['owner_id', 'promoter_id']);
and now i tray drop it
$table->dropUnique(['owner_id', 'promoter_id']);
General error: 1553 Cannot drop index 'connections_owner_id_promoter_id_unique': needed in a foreign key constraint (SQL: alter table connections drop index connections_owner_id_promoter_id_unique)
Also, i tried to drop foreign key before
$table->dropForeign('connections_promoter_id_foreign');
but still no results
A primary key or unique key index cannot be explicitly dropped.
In Object Explorer, right-click the table with the unique constraint, and click Design. On the Table Designer menu, click Indexes/Keys. In the Indexes/Keys dialog box, select the unique key in the Selected Primary/Unique Key and Index list. Click Delete.
The DROP CONSTRAINT command is used to delete a UNIQUE, PRIMARY KEY, FOREIGN KEY, or CHECK constraint.
The syntax for dropping a unique constraint in MySQL is: ALTER TABLE table_name DROP INDEX constraint_name; table_name. The name of the table to modify.
From Laravel docs on Indexes, you can create the unique index with an assigned name:
So just to save you of debugging how laravel constructs the name to the index, you may assign it a name when adding the index e.g:
$table->unique(['owner_id', 'promoter_id'], 'owner_promoter_index');
Then when you drop it, you use the same name:
$table->dropUnique('owner_promoter_index');
Based on this Drop muli-column unique key without dropping foreign key? i got this solution which also works:
Schema::table('connections', function ($table){
$table->index('owner_id');
$table->dropUnique(['owner_id', 'promoter_id']);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With