且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Laravel迁移“无法添加外键约束" MySQL数据库错误

更新时间:2023-12-01 09:39:16

这是因为您在迁移文件中添加了$table->integer('user_id');.您必须添加unsignedInteger而不是integer,因为users表的原始id列为unsigned(并且两列必须完全相同).

This is because you added $table->integer('user_id'); to your migration file. You must add an unsignedInteger instead of an integer, because the original id column of the users table is unsigned (and both columns must be exactly the same).

从Laravel 5.8开始,默认users表的id列类型不再是integer.现在是bigInteger.

Since Laravel 5.8, the id column type of the default users table is no longer an integer. It is now a bigInteger.