I have 2 tables:
_________ ____________
| users | | friends |
|_______| |__________|
| id | | id_user1 |
| nick | | id_user2 |
|____开发者_JAVA百科___| |__________|
But if I try to join them together, like
Alter table friends add Foreign Key (id_user1) references users (id) on delete restrict on update restrict;
Alter table friends add Foreign Key (id_user2) references users (id) on delete restrict on update restrict;
I get an Identical attribute name "id" in entity "friends"
error. How would I do this ?
This works for me:
CREATE TABLE users (id INT NOT NULL PRIMARY KEY) ENGINE=InnoDB;
CREATE TABLE friends (id_user1 INT NOT NULL, id_user2 INT NOT NULL) ENGINE=InnoDB;
Alter table friends add Foreign Key (id_user1) references users (id) on delete restrict on update restrict;
Alter table friends add Foreign Key (id_user2) references users (id) on delete restrict on update restrict;
精彩评论