Mysql – Need help about giving relationships in database design

database-designMySQLrdbmsrelational-theory

I am developing a simple blog application in which users can write posts and others can like, comment, share etc. i am facing difficulty in designing database.
What I have tried is:

user (user_id(pk), user_name)

post (post_id(pk), post_content, likes, user_id(fk))

comment(comment_id(pk), comment, post_id(fk))

PROBLEM: One user can have many posts and many users can like and comment on many posts. Whether I have to separate two tables like: user, post and userpost?

Can anyone tell me if anything wrong in this design?

Best Answer

Try something like this

user (user_id(pk), user_name)

post (post_id(pk),user_id(fk), post_content)

comment(comment_id(pk),post_id(fk),user_id(fk), comment)

likes(post_id(fk), user_id(fk) status)

In status column in likes table you can save it as like or unlike can be tinyint field with

NULL - Default value
True - Like and False - unlike(if you have unlike option)