Django With one admin function , It means Django By default, there are user management classes . This can also be done from Django See... In the table generated by default . as follows ：
mysql> SHOW TABLES; +----------------------------+ | Tables_in_kylin_ksrcdb | +----------------------------+ | auth_group | | auth_group_permissions | | auth_permission | | auth_user | | auth_user_groups | | auth_user_user_permissions | | captcha_captchastore |
In general , When we implement the custom user model , Will come from AbstractUser Inherit . Then implement our custom user model . for example ：
from django.db import models from django.contrib.auth.models import AbstractUser # Import AbstractUser # Create your models here. class Users(AbstractUser): ... class Meta: db_table = 'xxxx' # It's best to have a and Django The default table has different names verbose_name = ' User management ' verbose_name_plural = verbose_name
such ,model The definition is finished , Now you can generate the migration file , The migration was performed .
python3 manage.py makemigrations python3 manage.py migrate
You'll find out migrate Report errors 了 . Error is as follows ：
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency users.0001_initial on database 'default'.
1. Comment out the of the project setting.py In file INSTALLED_APPS In the list 'django.contrib.admin' 2. At the same time, you need to comment out the urls.py Medium urlpatterns In the list path('admin/', admin.site.urls) 3. perform migrate, I can't tell you wrong . 4. Just change the notes back . 5. perform runserver, Found that the project can run successfully
The above is the possible problems and solutions of user-defined model .
Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .