mysql - Foreign Key in SQL pivot table - database design -
i using dbdesigner 4 designing database relations.
i have users
table , recipes
table. 1 user can own many recipes 1 recipe cannot owned many users. relationship shown user_recipes
relation in picture. (a one-to-many relationship users
recipes
).
however, recipes can liked users. many users can many recipes. many-to-many relationship between users
, recipes
, pivot table users_like_recipes
.
but when create pivot table, need users_id
, recipes_id
column. recipes_users_id
column getting added on own , not able remove it. says third column has come relation defined in model. guess user_recipes
relation.
when remove user_recipes
relation, pivot table want to.
but need user_recipes
relation too!
please. appreciated.
i suggest removing user_id primary key from recipes table. combination if id , user_id provides identification recipes table. in situation multiple user_id's can create same recipe id because combination has unique. user_id can normal column in table. if want to, can make alternate key on (id, user_id) not need because id unique.
Comments
Post a Comment