【问题标题】:Django Auth User Model Set different field name for passwordDjango Auth用户模型为密码设置不同的字段名
【发布时间】:2019-06-21 05:42:15
【问题描述】:

我最近研究了 Django 框架并计划将我的旧系统迁移到其中。因此,我需要遵循遗留的 mysql 数据库。无论如何要更改 Django 用户模型的密码字段名称吗?例如“pwd”或“password2”。

我研究了 Django 文档,只发现更改了用户名字段 https://docs.djangoproject.com/en/2.2/topics/auth/customizing/#django.contrib.auth.models.CustomUser.USERNAME_FIELD

【问题讨论】:

    标签: django python-3.x


    【解决方案1】:

    我认为您可以创建一个继承自用户模型的新类并将密码字段设置为您喜欢的任何内容。

    类似:

    class MyUser(AbstractBaseUser):
        ...
        password = models.CharField(max_length=100, db_column='custom_name')
        ...
    

    【讨论】:

    • 特别是从 AbstractUser 派生,用 db_field= kwarg 重新声明 password 字段。
    猜你喜欢
    • 1970-01-01
    • 2011-02-28
    • 2020-01-12
    • 2019-01-01
    • 2020-05-21
    • 2014-04-25
    • 1970-01-01
    • 1970-01-01
    • 2011-04-12
    相关资源
    最近更新 更多