“General error: 1005 Can't create table” Using Laravel Schema Build and Foreign Keys

后端 未结 11 1150
予麋鹿
予麋鹿 2020-12-03 07:02

Essentially, I am having the same issue as this guy, minus the table prefix. Because I have no table prefix, his fix does not work. http://forums.laravel.com/viewtopic.php?i

11条回答
  •  悲&欢浪女
    2020-12-03 07:21

    I ran into this issue too.

    The solution I found is that the tables that contain the id that is being used a foreign id needs to be created before another table can reference it. Basically, you are creating a table and telling MySQL to reference another table's primary key but that table doesn't exist yet.

    In your example, the author and lesson tables need to be created first.

    The order in which the tables are created is dependent on artisan and the order you created your migration files.

    My opinion would be to empty out your database of all the tables and change the timestamps in the migration file names (or delete them and recreate them in the correct order) so that your author and lesson tables are created before your tutorials table.

提交回复
热议问题