[Python-Django model] migrate users to migrate database model (the same applies to other database migration)! ! !

 

Migrating User model class

1. The user specifies a model class

File

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

  1. User model based user authentication system, is determined by the configuration item AUTH_USER_MODEL global.
  2. If you migrate custom user model class, you must first configure AUTH_USER_MODEL.
 

Guess you like

Origin www.cnblogs.com/LiuXinyu12378/p/11258626.html