Search code examples
djangoabstractuser

How to change max_length of username in AbstractUser


Model.py

class User(AbstractUser):
  username = models.CharField(max_length=20)

Why does the phrase below appear in cmd?

WARNINGS: ourtube.User: (auth.W004) 'User.username' is named as the 'USERNAME_FIELD', but it is not unique. HINT: Ensure that your authentication backend(s) can handle non-unique usernames.


Solution

  • This is because you are not mentioning the unique=True in username fields.

      username = models.CharField(max_length=20)
    

    change to

          username = models.CharField(max_length=20, unique=True)