mstdmstd
Новичок
Всем привет,
В Laravel5.5 делаю миграцию с 2мя полями и индексом:
Которая успешно создается, но при выполнении отката ошибка(в мигарциях я стараюсь выполнять и откат для тестирования):
В откате индекс указан первым
Поле task_id - это ссылка на tasks таблицу Не пойму почему ошибка и как это сиправить ?
Спасибо !
В Laravel5.5 делаю миграцию с 2мя полями и индексом:
PHP:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class ModifyTaskAssignedToUsersIsLeaderStatus extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
try {
DB::beginTransaction();
Schema::table('task_assigned_to_users', function (Blueprint $table) {
$table->enum('status', ['A', 'C', 'N'])->comment(' A=>Accepted, C=>Canceled, N-New(Waiting for acception)')->after('user_id');
$table->boolean('is_leader')->default(false)->after('status');
$table->index(['task_id', 'status', 'is_leader'], 'task_assigned_to_users_task_id_status_is_leader_index');
});
} catch (Exception $e) {
DB::rollBack();
throw $e;
}
DB::commit();
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
try {
DB::beginTransaction();
Schema::table('task_assigned_to_users', function (Blueprint $table) {
$table->dropIndex('task_assigned_to_users_task_id_status_is_leader_index');
$table->dropColumn('status');
$table->dropColumn('is_leader');
});
} catch (Exception $e) {
DB::rollBack();
throw $e;
}
DB::commit();
}
}
PHP:
$ php artisan migrate:rollback
In Connection.php line 664:
SQLSTATE[HY000]: General error: 1553 Cannot drop index 'task_assigned_to_users_task_id_status_is_leader_index': needed in a foreign key constraint (SQL: alter table `tsk_task_assigned_to_users` drop index `task_assigned_to_users_task_id_status_is_leader_index`)
In PDOStatement.php line 107:
SQLSTATE[HY000]: General error: 1553 Cannot drop index 'task_assigned_to_users_task_id_status_is_leader_index': needed in a foreign key constraint
In PDOStatement.php line 105:
SQLSTATE[HY000]: General error: 1553 Cannot drop index 'task_assigned_to_users_task_id_status_is_leader_index': needed in a foreign key constraint
Поле task_id - это ссылка на tasks таблицу Не пойму почему ошибка и как это сиправить ?
Спасибо !