mysql创建外键约束报错【Bug Fix】Error : Can't create table '#sql-534

    xiaoxiao2025-11-03  10

    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 '#sql-534_185' (errno: 150)

    找了好多原因,总结可以列举如下,我的犯错的是4

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

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

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

    5、还有可能是是标的Table Type 不对,如分别为InnoDB 和MyISAM

    mysql 5.7版本报道错误提示是这样的:Error Code: 1215 Cannot add foreign key constraint

    --本篇文章转自:【Bug Fix】Error : Can't create table '#sql-534_185' (errno: 150)并做了些许修改。

    转载请注明原文地址: https://ju.6miu.com/read-1303804.html
    最新回复(0)