G
G
gorwhoami2020-08-04 12:12:46
Laravel
gorwhoami, 2020-08-04 12:12:46

What is the problem with migration?

Good day to all. There are two migrations. They are movies and genres. When you try to link and by id, this error appears:

General error: 1822 Failed to add the foreign key constraint. Missing index for constraint 'movies_genres_id_foreign' in the referenced table 'genres' (SQL: alter table `movies` add constraint `movies_genres_id_foreign` foreign key (`genres_id`) references `genres` (`id`))

Это код из create_movies_table(файл миграции)
$table->unsignedBigInteger('genres_id');
 $table->foreign('genres_id')->references('id')->on('genres');
------------------------------------------
А это из create_genres_table(файл миграции genres)
$table->unsignedBigInteger('id');
$table->string('name');
$table->timestamps();

By mistake, it’s not entirely clear what exactly the problem is. I hope I didn’t forget to write anything

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question