mysql创建外链失败1005错误解决方法
2015-10-16 18:20
821 查看
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`);
错误号: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`);
相关文章推荐
- mysql数据库时间字段CURRENT_TIME问题
- WINDOWS下更改MYSQL数据路径(datadir)后服务启动1067解决不能改变mysql数据库存储位置
- 几个常见的MySQL性能测试工具
- mysql安装及配置服务
- MySQL找出表中重复字段的内容
- MySQL SQL语句优化的10条建议
- MySql 查询优化
- 查询练习mysql
- 【Mysql学习笔记】DDL、DML、DCL区别
- mysql 函数大全
- MYSQL SQL表操作
- 超级简单的mysql主从数据库配置攻略以及错误处理
- Ubuntu下mysql数据库自动备份脚本
- MySQL(17):Select-union(联合查询)使用注意事项
- MySQL的事务处理及隔离级别
- MySQL(16):Select-union(联合查询)
- MySQL(15):Select-distinct(返回非重复的记录)
- 数据库中间件扩展 MySQL 集群:kingshard
- MySQL数据库的存储结构
- 采用keepalived施工可用性MySQL-HA