开发者

creating a 'users' and 'friends' relationship

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜