Followers/following database structure

后端 未结 4 1966
臣服心动
臣服心动 2021-01-31 05:52

My website has a followers/following system (like Twitter\'s). My dilemma is creating the database structure to handle who\'s following who.

What I came up with was crea

4条回答
  •  终归单人心
    2021-01-31 06:32

    That's the worst way to do it. It's against normalization. Have 2 seperate tables. Users and User_Followers. Users will store user information. User_Followers will be like this:

    id | user_id | follower_id
    1  | 20      | 45
    2  | 20      | 53
    3  | 32      | 20
    

    User_Id and Follower_Id's will be foreign keys referring the Id column in the Users table.

提交回复
热议问题