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

标签 php laravel laravel-4 laravel-5 database-migration

我这样做是为了使我的电子邮件字段在表中唯一

$table->unique('email');

我试过了

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

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

enter image description here

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

enter image description here

如何编写迁移来撤消它?

最佳答案

你必须做 $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.

关于php - 如何编写迁移以撤消 Laravel 中的唯一约束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30607670/

相关文章:

mysql - 在 MySQL 中存储 JSON 有什么负面影响吗?

php - 检查表1中的用户名并返回表2中的数据

amazon-web-services - 亚马逊 EC2 Laravel 应用程序无法正常工作

php - 拉维尔 4 : Prevent form re-submissions

templates - Laravel Blade 模板,URL::to 中的 foreach 变量?

php - 使用 nginx 在服务器上部署 laravel 出现 500 错误

laravel - 如何检查 Laravel 中队列的状态?

php - 将 JS 创建的输入文本框的值插入数据库

javascript - 复选框不起作用

javascript - 当数据库img标签中没有条目时仍然显示空框