Я попытался создать блог и заблокирован из-за ошибки при переносе одной таблицы.
Я пытался изменить порядок создания внешнего ключа,
чтобы встроить два внешних ключа в один с массивом,
$table->foreign(['commentary_id', 'post_id'])->references(['id', 'post_id'])->on('commentaries');
Комментарии по миграции
$table->integer('post_id')->unsigned();
$table->integer('id')->unsigned();
$table->string('content');
$table->integer('user_id')->unsigned();
$table->timestamps();
$table->primary(['post_id', 'id']);
$table->foreign('post_id')->references('id')->on('posts');
$table->foreign('user_id')->references('id')->on('users');
Ответы Миграция
$table->integer('post_id')->unsigned();
$table->integer('commentary_id')->unsigned();
$table->integer('id')->unsigned();
$table->string('content');
$table->integer('user_id')->unsigned();
$table->timestamps();
$table->primary(['post_id', 'commentary_id', 'id']);
$table->foreign(['commentary_id', 'post_id'])->references(['id', 'post_id'])->on('commentaries');
$table->foreign('user_id')->references('id')->on('users');
И ошибка, которую я получил:
General error: 1005 Can't create table `blog-lurius`.`responses`
(errno: 150 "Foreign key constraint is incorrectly formed")
(SQL: alter table `responses` add constraint `responses_commentary_id_post_id_foreign` foreign key (`commentary_id`, `post_id`) references `commentaries` (`id`, `post_id`))
Я ожидаю, что в моей миграции не будет фатальной ошибки. Где оба моих внешних ключа эффективны.