SQLSTATE [HY000]: General error: 1215 Cannot add foreign key constraint
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `categories` add constraint `categories_parent_id_foreign` foreign key (`parent_id`) references `categories` (`id`) on delete cascade)
运行迁移文件的时候报这个错,查了下是由于主外键之间的数据类型不一致造成的。
mysql版本是5.7.22,不知道其他同学有没有遇到过。
把
$table->unsignedInteger('parent_id')->nullable();
改成
$table->unsignedBigInteger('parent_id')->nullable();
就好了
推荐文章: