首页 > 其他 > 详细

Django-组件--用户认证Auth(auth_user增加字段)

时间:2018-11-06 00:21:21      阅读:304      评论:0      收藏:0      [点我收藏+]

引入:


from django.db import models
from django.contrib.auth.models import AbstractBaseUser

源码 :

from django.contrib.auth.models import User  
(user指的是 auth_user表)
User源码=====》
class User(AbstractUser):
    """
    Users within the Django authentication system are represented by this
    model.

    Username and password are required. Other fields are optional.
    """
    class Meta(AbstractUser.Meta):
        swappable = AUTH_USER_MODEL

 

一:增加 auth_user 表的字段

1:setting设置

AUTH_USER_MODEL="app01.UserInfo"     #表示哪张表继承了auth_user表(在给auth_user添加字段用到)

2:增加表字段

from django.contrib.auth.models import AbstractUser

class UserInfo(AbstractUser):
    r_pwd=models.CharField(max_length=32)

3:数据库迁移

python manage.py makemigrations    #同步
python manage.py migrate

4:效果

auth_user 表名被改为  auth_userinfo。且添加了一个字段

 5. 数据迁移

makemigrations users 会出错,django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency users.0001_initial on database default.

技术分享图片

 

 

 

 

 

 

 



直接:

makemigrations
migrate

 












Django-组件--用户认证Auth(auth_user增加字段)

原文:https://www.cnblogs.com/heshun/p/9912405.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!