我目前正在尝试学习 mysql,我在引用外键部分,但似乎无法让它接受它。 我错过了什么?希望你能帮忙:)
mysql> create table states (
-> id tinyint(3) not null primary key auto_increment,
-> name varchar(255));
Query OK, 0 rows affected (0.02 sec)
mysql> create table customers (
-> id integer(10) not null auto_increment primary key,
-> name varchar(255) not null,
-> email varchar(255) not null,
-> states_id tinyint unsigned not null,
-> foreign key(states_id) references states(id) on update cascade);
ERROR 1215 (HY000): Cannot add foreign key constraint
最佳答案
通过外键关联的列需要具有相同的数据类型。 id 是 TINYTINT(3) 但 states_id 是 TINYTINT UNSIGNED。
重新定义你对状态的定义,然后再试一次。
关于MySQL 错误 1215 (HY000) : Cannot add foreign key constraint state_id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22544891/