Auth用户
1.声明用户表
djangauth/settings.py
..............................
AUTH_USER_MODEL = 'app01.UserInfo'
2.定义用户表
app01/models.py
..............................
from django.db import models
# Create your models here.
from django.contrib.auth.models import AbstractUser
class UserInfo(AbstractUser):
"""
用户信息表
"""
nid = models.AutoField(primary_key=True)
phone = models.CharField(max_length=11, null=True, unique=True)
def __str__(self):
return self.username
3.数据库迁移
python manage.py makemigrations
python manage.py migrate
4.查看生成用户表
-- auto-generated definition
create table app01_userinfo
(
password varchar(128) not null,
last_login datetime(6) null,
is_superuser tinyint(1) not null,
username varchar(150) not null,
first_name varchar(30) not null,
last_name varchar(150) not null,
email varchar(254) not null,
is_staff tinyint(1) not null,
is_active tinyint(1) not null,
date_joined datetime(6) not null,
nid int auto_increment
primary key,
phone varchar(11) null,
constraint phone
unique (phone),
constraint username
unique (username)
);