请教一下外键约束出现的问题,提示不兼容,应该怎么解决呢?
请教一下大家。我添加外键约束
Schema::table('supply_infos', function (Blueprint $table) {
// 当 user_id 对应的 users 表数据被删除时,删除供应信息
$table->unsignedInteger('user_id')->change();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});
出现这个问题。提示是不兼容。
SQLSTATE[HY000]: General error: 3780 Referencing column 'user_id' and referenced column 'id' in foreign key constraint 'supply_infos_user_id_foreign' are incompatible. (SQL: alter table `supply_infos` add constraint `supply_infos_user_id_foreign` foreign key (`user_id`) references `users` (`id`) on delete cascade)
user 表的字段是这样的
$table->id();
supply_infos 表的字段是这样的
$table->integer('user_id')->comment('所属用户');
字段类型
user表是bigint类型
其他表的user_id 是int类型
请问应该怎么解决呢
乌鸦嘴社区 wyz.xyz 来玩。
推荐文章: