gpt4 book ai didi

python - Django 模型迁移在使用 AbstractBaseUser 类时添加了两个不需要的字段

转载 作者:行者123 更新时间:2023-11-29 20:23:55 24 4
gpt4 key购买 nike

Django 1.9
Python 3.4

我使用 AbstractBaseUser 类创建了一个自定义用户模型。下面是代码。

class UserModel(AbstractBaseUser):
# custom user class
SYSTEM = 0
TENANT = 1
parent_type_choices = (
(SYSTEM, 'System'),
(TENANT, 'Tenant')
)
sys_id = models.BigIntegerField(primary_key=True, blank=False)
parent_type = models.PositiveIntegerField(choices=parent_type_choices, null=False, blank=False)
parent_sys_id = models.ForeignKey('tenant.TenantModel', on_delete = models.SET_NULL, null=True, blank=True)
last_name = models.CharField(null=False, blank=False, max_length=40)
first_name = models.CharField(max_length=40, null=False, blank=False)
display_name = models.CharField(max_length=80, unique=True, null=False, blank=False)
login = models.CharField(max_length=40, unique=True, null=False, blank=False)
authentication_method = models.CharField(max_length=80)
pwd = models.CharField(max_length=40)
access_valid_start = models.DateTimeField()
access_valid_end = models.DateTimeField()
created_when = models.DateTimeField()
created_by = models.BigIntegerField()
last_updated_when = models.DateTimeField()
last_updated_by = models.BigIntegerField()
notes = models.CharField(max_length=2048)

USERNAME_FIELD = "login"

class Meta:
app_label = "accounts"
db_table = "Users"

当我迁移更改时,在数据库中创建了表,其中包含两个我未定义的额外字段。添加了密码last_login

desc Users;
+-----------------------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+------------------+------+-----+---------+-------+
| password | varchar(128) | NO | | NULL | |
| last_login | datetime | YES | | NULL | |
| sys_id | bigint(20) | NO | PRI | NULL | |
| parent_type | int(10) unsigned | NO | | NULL | |
| last_name | varchar(40) | NO | | NULL | |
| first_name | varchar(40) | NO | | NULL | |
| display_name | varchar(80) | NO | UNI | NULL | |
| login | varchar(40) | NO | UNI | NULL | |
| authentication_method | varchar(80) | NO | | NULL | |
| pwd | varchar(40) | NO | | NULL | |
| access_valid_start | datetime | NO | | NULL | |
| access_valid_end | datetime | NO | | NULL | |
| created_when | datetime | NO | | NULL | |
| created_by | bigint(20) | NO | | NULL | |
| last_updated_when | datetime | NO | | NULL | |
| last_updated_by | bigint(20) | NO | | NULL | |
| notes | varchar(2048) | NO | | NULL | |
| parent_sys_id_id | bigint(20) | YES | MUL | NULL | |
+-----------------------+------------------+------+-----+---------+-------+

为什么会发生这种情况?如何删除这些字段?

最佳答案

您继承自提供这些字段的 AbstractBaseUser 类。您无法删除它们。检查Django doc了解更多信息

关于python - Django 模型迁移在使用 AbstractBaseUser 类时添加了两个不需要的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39407225/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com