Skip to content Skip to sidebar Skip to footer

Django, How Does Models.py Under Auth Folder Create Initial Tables When You Migrate Very First Time?

If you migrate very first time after making new project in Django, you can find that Django creates tables like below. auth_group auth_group_permissions auth_permission auth_user a

Solution 1:

This can be easily explained.

auth_user_groups
auth_group_permissions
auth_user_user_permissions

Are relational tables. Which are used to store info about how model tables are related.

For example auth_user_groups is storing how users and groups are related. If you do

SELECT * FROM auth_user_groups;
|id|user_id|group_id|
....

And here we can see that which groups are related to which users.

So basically django will automatically create such tables for when you use ManyToManyField on your models

Answering comment Django migration table is created automatically when you call ./manage.py migrate for the first time. This table stores history of applying your migrations. Migration model can be found in django/db/migrations/recorder.py. This model is used when running new migrations to see which are applied and which should be applied on this command run. And this model is part of core django's functionality, that's why you don't need to add it in INSTALLED_APPS because INSTALLED_APPS contain only pluggable apps. Which you can include/exclude from your project if you want.


Post a Comment for "Django, How Does Models.py Under Auth Folder Create Initial Tables When You Migrate Very First Time?"