alter table abc add column cd_id bigint default null;
alter table abc add CONSTRAINT `FK_CD_ID` FOREIGN KEY (`CD_ID`) REFERENCES `cd` (`id`) ON DELETE set null;
ERROR 1005 (HY000): Can't create table 'vcread.#sql-9ec_e14a' (errno: 150)
Cannot find an index in the referenced table where the referenced columns appear as the first columns, or column types in the table and the referenced table do not match for constraint.
(译:不能在“被reference的表”里找到包含“被reference字段”的索引,或者是两个关联字段类型不匹配)
cd表的id类型为int(11), 外键字段定义为了bigint。所以。。。
本文介绍了一种常见的数据库外键约束错误,即当定义的外键类型与引用表中的主键类型不符时出现的问题。通过具体示例展示了如何诊断此类问题,并给出了相应的解决方案。
2246

被折叠的 条评论
为什么被折叠?



