如何编写迁移以撤消 Laravel 中的唯一约束?

How to write a migrate to undo the unique constraint in Laravel?

我这样做是为了让我的电子邮件字段 unique 在 table 中。

$table->unique('email');

我试过了

public function up()
{
    Schema::table('contacts', function(Blueprint $table)
    {
        $table->dropUnique('email');
    });
}

然后,当我 运行 php artisan 迁移时,我得到了这个

它告诉我它不在那里,但我 100% 确定它在那里。

如何编写迁移来撤消它?

你必须做$table->dropUnique('users_email_unique');

To drop an index you must specify the index's name. Laravel assigns a reasonable name to the indexes by default. Simply concatenate the table name, the names of the column in the index, and the index type.

这是放弃独特性的更好方法。您可以在此处使用真实的列名。

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