django抛出唯一约束即使添加unique = false失败了
我正在使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在上面的代码中,迁移不应有任何问题。我认为您的旧迁移在这里造成问题。检查您的旧迁移并删除它们。
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.