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?
用户、角色、功能、三张表分开就好了
用户对应角色、角色对应功能、
角色现在就是普通用户和管理员、那查的时候根据角色关联一下就知道需不需要判断密码了
不同的功能也根据角色分配、在关联表里面加
只是个人博客而已,User只需要记录自己的登录信息就好,普通用户既然只能评论,那就不需要有登录的功能,普通用户的用户名或者邮箱就记录在comment里面就好啦,post跟comment是一对多的关系,就不需要涉及到跟用户的关系啦
看你的描述,你纠结的一点是数据库里会因为普通用户不需要password而管理员需要password,而管理员只有你一个~~我个人想到的方式就是数据库存储和设计按照一楼“liujijans”的方式,不过可以在库里不用加上password,然后admin的这个password可以设置为动态的,比如一个你预先设置的前缀+当天日期,这样的密码安全度还是有的,然后也比较好记,不需要在代码里刻意的设置。关于权限系统、用户中心还有实际的业务可以分开来设计,解耦之后不但灵活,而且业务模块化比较有架构性,哈哈,装逼范儿十足。