search

Home  >  Q&A  >  body text

python - Problems with personal blog database design

I need to design a personal blog, and I have encountered difficulties in database design.
The function I want to implement is: ordinary users can only comment on blogs. The administrator (that's me) can log in, post blogs, and reply to comments.

Originally designed, the tables have User, Admin, Post, and Comment.
But User and Comment are one-to-many, and Admin and Comment are also one-to-many. This will make it messy.

So I want to merge the User table and Admin table into one table, called User, but the administrator needs a password field, but ordinary users do not need it. There is only one administrator, but there are many ordinary users, so the design is wasteful. a field.

Please give me some suggestions on how to design the User and Admin tables.
In addition, I want to learn database design. Please recommend some information. Because I have seen a lot of information on database operations, but how is the database designed?

typechotypecho2739 days ago879

reply all(3)I'll reply

  • 迷茫

    迷茫2017-06-28 09:25:13

    Users, roles, functions, and three tables can be separated

    User corresponding roles, role corresponding functions,

    The roles are now ordinary users and administrators. When checking, you will know whether you need to determine the password by correlating the roles.

    Different functions are also assigned according to roles and added to the association table

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-06-28 09:25:13

    It’s just a personal blog. Users only need to record their login information. Since ordinary users can only comment, there is no need to log in. The username or email address of ordinary users can be recorded in the comment. Post There is a one-to-many relationship with comment, so there is no need to involve the relationship with users

    reply
    0
  • 天蓬老师

    天蓬老师2017-06-28 09:25:13

    Looking at your description, the point you are struggling with is that ordinary users do not need passwords but administrators need passwords in the database, and you are the only administrator~~ The way I personally think of is that the database storage and design is according to "liujijans" on the first floor method, but you don’t need to add a password in the library, and then the admin password can be set to be dynamic, such as a prefix you set in advance + today’s date. This kind of password is still more secure, and it is easier to remember. No need to set it deliberately in the code. The permission system, user center and actual business can be designed separately. After decoupling, it is not only flexible, but also the business modularization is more structured. Haha, it is full of pretentious style.

    reply
    0
  • Cancelreply