嘗試創建沒有電子郵件的第二個用戶時,出現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