Migrating User model class
1. The user specifies a model class
Question: Why Django model default user class is User?
- Read the source code: 'django.conf.global_settings'
AUTH_USER_MODEL = 'auth.User'
in conclusion:
- Django User model class is determined by the configuration item AUTH_USER_MODEL global
Configuration rules: be configured in setting.py
AUTH_USER_MODEL = '应用名.模型类名'
# 指定本项目用户模型类
AUTH_USER_MODEL = 'users.User'
2. Migrate User model class
1. Create a file migration
-
python manage.py makemigrations
2. perform the migration file
-
python manage.py migrate
3. Knowledge Points
- User model based user authentication system, is determined by the configuration item AUTH_USER_MODEL global.
- If you migrate custom user model class, you must first configure AUTH_USER_MODEL.