database design for 'followers' and 'followings'?

后端 未结 4 1625
醉话见心
醉话见心 2020-12-23 00:01

Dear database experts/programmers:

I have a mysql table with users information, such as

id      user_id         name etc.
1       userA            
2         


        
4条回答
  •  心在旅途
    2020-12-23 00:39

    In general, your design is correct.

    But, if user_id is unique in the table "users", you don't need the column "id" in "users". (A single table containing a unique "id" and a unique "user_id" is pretty unusual.) You also don't need the column "id" in the table "followers".

    Primary key in "followers" should be (user_id, follower_id), and make sure each of those columns has a foreign key referencing "user_id" in "users".

提交回复
热议问题