简体   繁体   中英

Database design for blog

I'm looking for the best way to design database for simple blog. My idea is:

  • Posts table - contains id, content, etc.,
  • Categories - contains category id, name, link-name (simple name used for example in routes),
  • Tags - tag id, tag name, link-name,
  • CategoriesMap - contains post id and category id, post may have a few categories,
  • TagMap - as above.

Is it good solution? I use Symfony3 with Doctrine and MySQL.

In addition to the tables above, I recommend you add the following tables:

  1. staff: a table for staff which may include fields like: id, name, role (Author, Editor, etc), email, password, photo etc. Then add the staff id on the Posts table.
  2. visitor: a table of visitors is not a bad idea either. It have have fields like visitor id, name(null=YES), email(null=YES), subscription(YES/NO/NULL), ip_address(null=YES), favorite_category(null=YES) etc.
  3. comment: In addition, you may want to have a comment table where you have fields like: id, message, visitor_id, post_id etc.

A user table should be there to track the post authors and to implement a login/registration system. The same table can be used to securely manage the blog posts.

Also, comment system is an integral part of a blogging system. You can either have a table to store comments or integrate an external commenting system.

You can also check this ER Diagram to have more clarity about what I am saying.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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