Mysql创建外键约束时,报errno: 150

本文介绍了一种常见的数据库外键约束错误,即当定义的外键类型与引用表中的主键类型不符时出现的问题。通过具体示例展示了如何诊断此类问题,并给出了相应的解决方案。

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。所以。。。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值