[Django]-Django, How does models.py under auth folder create initial tables when you migrate very first time?

3👍

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.

Leave a comment