【Bug Fix】Error : Can't create table 'moshop_1.#sql-534_185' (errno: 150)

运行alter操作,

alter table xx_shop_info add index FK9050F5D83304CDDC (shop_area), add constraint FK9050F5D83304CDDC foreign key (shop_area) references xx_shop_area (id)

出现下面的错误

Error : Can't create table 'moshop_1.#sql-534_185' (errno: 150)


找了好多原因,总结能够列举例如以下,我的犯错的是5

1、外键的引用类型不一样,主键是int外键是char 

2、找不到主表中 引用的列 

3、主键和外键的字符编码不一致 
4、还有要建立外键的话,要先建立索引。没有建立索引也会出错。

5、还有可能是是标的Table Type 不正确,例如以下的InnoDB 和MyISAM的错误


原文地址:https://www.cnblogs.com/zfyouxi/p/4239830.html