简体   繁体   中英

How to handle user permissions in a database schema?

I'm currently creating a database model for a system containing users, which can have permissions to some categories. Simplified, it looks like this:

User
- username
- password

Category
- name

I now want to give users permissions to some categories, but not to others. So I thought of doing this like so:

User
- username
- password

Category
- name

Permission
- ForeignKeyField(username)
- ForeignKeyField(Category)

My question: is this a logical way or are there better or more usual ways of doing this?

The only thing I see missing are ID's. I would have my Schema set up as such:

User
- ID
- Username
- Password

Category
- ID
- Name

Permission
- ID
- UserID
- CategoryID

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