django抛出唯一约束即使添加unique = false失败了

发布于 2025-02-11 01:35:41 字数 745 浏览 3 评论 0原文

我正在使用Abstractuser开发一个自定义的USERMODEL,用于在Django的应用程序。 但是,使用添加django admin添加用户 +时,我会收到一个唯一的约束失败错误。 我还尝试在电子邮件field

class User(AbstractUser):
    id = models.BigAutoField(primary_key=True)
    rollno = models.CharField(null=True,unique=True,max_length=15)
    email = models.EmailField(blank=True,null=True,unique=False) 

错误中添加unique = false

....
    return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: UNIQUE constraint failed: Accounts_user.email
[28/Jun/2022 05:54:58] "POST /admin/Accounts/user/add/ HTTP/1.1" 500 233697

添加表格没有电子邮件字段,提交空白电子邮件。

(PS:我可以通过我的应用程序的注册表格添加用户,更改Django Admin的用户也正在工作。)\

I am developing a custom usermodel for my application in django, by using AbstractUser.
But I am getting a UNIQUE constraint failed error while using add user + from django admin.
I have also tried to add unique = False in the EmailField

class User(AbstractUser):
    id = models.BigAutoField(primary_key=True)
    rollno = models.CharField(null=True,unique=True,max_length=15)
    email = models.EmailField(blank=True,null=True,unique=False) 

Error :

....
    return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: UNIQUE constraint failed: Accounts_user.email
[28/Jun/2022 05:54:58] "POST /admin/Accounts/user/add/ HTTP/1.1" 500 233697

The add form does not have a email field, submits a blank email.

(PS : I can add user by signup form of my application, change user of django admin is also working.)\

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘和柠 2025-02-18 01:35:41

在上面的代码中,迁移不应有任何问题。我认为您的旧迁移在这里造成问题。检查您的旧迁移并删除它们。

in the above code, there should not be any problem with migrations. i think your old migrations are creating problem here. check your old migrations and delete them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文