ERRORS:*: (auth.E003) ‘User.username‘ must be unique because it is named as the ‘USERNAME_FIELD

在找一个唯一索引字段 例: email

class MyUser(AbstractUser):
    username = models.CharField(max_length=30, unique=False)
    email = models.EmailField(max_length=255, unique=True)
    USERNAME_FIELD = 'email'

如果您使用可支持它的自定义身份验证后端,则允许使用非唯一的用户名字段。

如果要使用django的默认身份验证后端,则无法使用户名非唯一。

您必须使用get_user(user_id)实现一个类,并为自定义后端实现身份验证(请求,**凭据)方法。
https://docs.djangoproject.com/zh-hans/3.1/topics/auth/customizing/

你可能感兴趣的:(django)