0

I currently have a many-to-many relationship as shown below:

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)
);

I'm trying to add a One-to-many relationship using the code below:

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

, but it keeps giving me this error:

ERROR 1215 (HY000): Cannot add foreign key constraint

I'm really not sure what I'm doing wrong.

slimboy
  • 1,633
  • 2
  • 22
  • 45

0 Answers0