我必须使用Laravel迁移从电子邮件列中删除唯一约束。这是我的代码:
class AlterEmailToUsers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('email')->unique(false)->nullable()->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->string('email')->nullable(false)->unique()->change();
});
}
}
但是,当我运行
php artisan migrate
时,出现以下错误:SQLSTATE[42000]: Syntax error or access violation: 1061 Duplicate key name 'users_email_unique' (SQL: alter table `users` add unique `users_email_unique`(`email`))
最佳答案
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('email')->unique(false)->nullable()->change();
});
}
改成
$table->dropUnique('users_email_unique');
关于laravel - 如何使用Laravel迁移从列中删除唯一约束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49811807/