无法使用一对多关系添加外键约束

时间:2017-03-03 19:36:56

标签: mysql

我目前有多对多的关系,如下所示:

Create table users( 
   id bigint AUTO_INCREMENT,
   primary key (id)
);

CREATE TABLE users_friends(
   id bigint,
   friend_id  bigint,
   Primary Key (id,friend_id), 
   Foreign Key (id) REFERENCES users(id),
   Foreign Key (friend_id) REFERENCES users(id)
);

我正在尝试使用以下代码添加一对多关系:

CREATE TABLE requests(
        id int primary key auto_increment, 
                 user_id int not null,
                 Foreign Key (user_id) references users(id)
);

,但它一直给我这个错误:

  

ERROR 1215(HY000):无法添加外键约束

我真的不确定我做错了什么。

0 个答案:

没有答案
相关问题