Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

loreias's avatar

Remove Unique with migration

Hi guys got a question about migrations, I need to remove a unique constrain from a table without refresh the db. how could i do that ?

$table->integer('user_id')->unsigned()->index()->unique();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

How can i update the user_id row to remove the unique constrain using migrations.

Thanks guys for any help you can give me, must appreciated.

0 likes
4 replies
forrestt's avatar

I came here looking for how to undo an attribute, but I couldn't find how to undo an attribute on the linked page. I found this on stack overflow, you have to add (false) to the unique field before using ->change:

$table->integer('user_id')->unique(false)->change();
slawe's avatar

If someone try same

$table->dropUnique('tablename_column_unique');
2 likes
Ntwari's avatar

simply delete the unique key with the column name

$table->dropUnique(['email']);

1 like

Please or to participate in this conversation.