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



你可能感兴趣的:(mysql,table,delete,reference,Types)