mysql创建外链失败1005错误解决方法

您所在的位置:网站首页 代码1005 mysql创建外链失败1005错误解决方法

mysql创建外链失败1005错误解决方法

2023-12-20 12:47| 来源: 网络整理| 查看: 265

mysql创建外链失败1005错误解决方法

错误号:1005错误信息:Can't create table 'webDB.#sql-397_61df' (errno: 150)解决方法

错误原因有四:

1、外键的引用类型不一样,主键是int外键是char,或者大小不一样也不行,int(11位) bigint(20位)2、找不到主表中 引用的列3、主键和外键的字符编码不一致4、要先建立索引,没有建立索引也会出错。

本人错误原因是1,将外键所在的表的字段为int改成跟主表一致的bigint就不报这个错误了。

已执行的 SQL 语句:Alter table `webDB`.`adm_house_layout` add constraint `FK_Relationship_911` foreign key (`house_type_id`) references `webDB`.`adm_recommend_house`(`r_id`)错误号:1005错误信息:Can't create table 'webDB.#sql-397_61df' (errno: 150)

错误号:1452错误信息 Cannot add or update a child row: a foreign key constraint fails (`webDB`.`#sql-397_61df`, CONSTRAINT `FK_Relationship_91` FOREIGN KEY (`house_type_id`) REFERENCES `adm_recommend_house` (`r_id`)) : a foreign key constraint fails (`webDB`.`#sql-397_61df`, CONSTRAINT `FK_Relationship_91` FOREIGN KEY (`house_type_id`) REFERENCES `adm_recommend_house` (`house_type_id`))

主表和依赖表的关系要弄清楚alter table adm_house_layout add constraint FK_Reference_91 foreign key (house_type_id) references adm_recommend_house (house_type_id) on delete restrict on update restrict;要反过来才行Alter table `webDB`.`adm_recommend_house` add constraint `FK_Relationship_91` foreign key (`house_type_id`) references `webDB`.`adm_house_layout`(`house_type_id`);



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3