gpt4 book ai didi

python - Django AbstractEmailUser 模型列不存在

转载 作者:太空宇宙 更新时间:2023-11-04 04:58:13 29 4
gpt4 key购买 nike

我创建了一个 CustomUser 模型,继承自 AbstractEmailUser。
我想在完成并进行迁移后添加一个头像字段,但出现以下错误:

column account_customuser.avatar does not exist
LINE 1: ...user"."name", "account_customuser"."valid_email", "account_c...

models.py 现在看起来像这样

class CustomUser(AbstractEmailUser):
nickname = models.CharField('nickname', max_length=100, unique=True)
name = models.CharField(max_length=200, blank=True, null=True, default=None)
valid_email = models.BooleanField('valid email', default=False, blank=True)
avatar = models.ImageField(upload_to='profile/photo', blank=True, null=True, default=None)

如何正确添加头像字段?

最佳答案

如此处所述:Django Programming error column does not exist even after running migrations

您的迁移过程中可能出了点问题。

  1. 转到您的数据库并找到一个名为 django_migrations 的表,其中列出了所有迁移。
  2. 找到包含您将 avatar 列添加到模型的迁移的行,并将其从数据库中删除(仅该行)。
  3. 再次迁移:./manage.py migrate

另一种可能性是您正在使用 Django Toolbar,就像这里发生的那样:Django Migration Error: Column does not exist ,在这种情况下,您需要在已安装的应用程序中评论工具栏并重新运行迁移。

关于python - Django AbstractEmailUser 模型列不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46521241/

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