简体   繁体   English

如何设计博客系统数据库?

[英]How to design database for blog system?

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 ? 我是否必须分开两个表,例如: userpostuserpost

Can anyone tell me if anything wrong in this design? 谁能告诉我这个设计有什么问题吗?

Your comment table is missing field which indicates user who added this comment. 您的comment表缺少字段,该字段指示添加此评论的用户。

And also it may be good idea to join posts and comments into one table - as comment is just a kind of post. 另外,将postscomments合并到一个表中也是一个好主意-因为评论只是一种帖子。 So you will need just to store parent_id of post being commented in the record for comment. 因此,您只需要在记录中存储要评论的帖子的parent_id即可进行评论。

And likes should be in another one table for many-to-many relationship of users and posts they like. 对于用户和他们喜欢的帖子之间的多对多关系, likes应该放在另一个表中。

So your tables can look like: 因此,您的表可能如下所示:

users (user_id(pk), user_name)

posts (post_id(pk), parent_post_id(fk), date, post_content, user_id(fk))

likes (like_id(pk), post_id(fk), user_id(fk))

Like someone mentioned above. 就像上面提到的某人。 It would be better to have Ratings in another table 最好在另一个表中包含“等级”

Ratings (Ratings_id(pk), user_id(fk), Post_id)

Something like the above. 像上面的东西。

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM