尝试创建没有电子邮件的第二个用户时,出现duplicate key value violates unique constraint "users_user_email_key" DETAIL: Key (email)=(None) already exists.
错误。Django唯一字段引发错误为无值
电子邮件字段定义:
email = models.EmailField(verbose_name='email address', max_length=255, unique=True, null = True, blank = True)
从形式创建用户:
def clean_email(self):
email = self.cleaned_data.get('email')
if email:
if email == "":
return None
else:
return email
else:
return None
我在做什么错在这里?所有的意见都表示赞赏,谢谢!
remove unique = True并检查'clean_mail'上的重复内容 – Meska