Removing unique constraint from a column using Laravel Migrations
I have to remove a unique constraint from an email column using Laravel Migrations. Here is my code.I required doctrine/dbal in composer.json is it necessary to use it in migration files too or it will be called automatically.
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();
});
}
}
But when I run migrate command I face the following error
SQLSTATE[42000]: Syntax error or access violation: 1061 Duplicate key name 'users_email_unique' (SQL: alter table `users` add unique `users_email_unique`(`email`))
from Laravel Questions and Answers https://laravelquestions.com/laravel/removing-unique-constraint-from-a-column-using-laravel-migrations/
via Lzo Media
No comments:
Post a Comment