mysql 错误 "cannot add foreign key constraint"

mysql error "cannot add foreign key constraint"

这里是 mysql 查询:

ALTER TABLE wp_juices_members
ADD CONSTRAINT fk_juiceid FOREIGN KEY(juice_id) REFERENCES wp_juices(id)

所有表、字段都存在上述查询中指定的正确名称,但我仍然收到此错误:

"cannot add foreign key constraint"

这是两个表的 DESC:

wp_juices_members:

Field       Type    Null    Key Default Extra   
id          int(11) unsigned    NO  PRI NULL    auto_increment
member_id   int(11) YES     NULL    
juice_id    int(11)

wp_juices:

Field   Type    Null    Key Default Extra   
id  int(11) unsigned    NO  PRI NULL    auto_increment
name    varchar(255)    NO      NULL    

更新:其实我已经弄明白了,被匹配的字段必须是相同的类型,形容词如无符号或不为空等。谢谢大家的帮助。

您可能想要添加对您正在使用的 table 的描述 DESC table_name 然后更新您的问题。

最常见的原因是您要 link 引用的每个列中 digit 的数量可能 INT(11) UNSIGNEDINT(11) SIGNED 不同会产生很大的不同。