I have lots of migrations and usually use 'php artisan migrate:refresh' and everything is fine.
For the first time I get an error while rollbacking because of a duplicate entry for a unique column:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'record' for key 'objects_key_unique' (SQL: alter table `objects` add unique `objects_key_unique`(`key`))
At first the column was unique but in a later migration I removed that constraint and now I have duplicate entries in my database.
The migration throws an error when I rollback because of the down function where the unique constraint is set again.
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class EditObjectTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('objects', function (Blueprint $table) {
$table->dropUnique(['key']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('objects', function (Blueprint $table) {
$table->unique(['key']);
});
}
}
How can I handle this? I do not want the column to have a unique constraint, but I also want to rollback without getting an error. Shortly after the "EditObjectTable" the table is dropped in another migration, so i do not need the data when I rollback.