Skip to content Skip to sidebar Skip to footer

Change Username Max_length In Django 1.11 (django.contrib.auth)

My users are using e-mail addresses as usernames, which caused a problem in Django 1.9 because there was a 30 character maximum username length. This was supposed to be fixed by Dj

Solution 1:

One way to allow custom length of username field is to use custom user model. The documentation is here: https://docs.djangoproject.com/en/1.11/topics/auth/customizing/#specifying-a-custom-user-model

Extend your custom user model from AbstractBaseUser which provides necessary methods to work with Django authentication.

Basically you can just create the model with data you need to have and define the required fields in the model. In your case you might want to set the USERNAME_FIELD and EMAIL_FIELD to be the same field in model.

Solution 2:

Django 1.10 shipped with a migration to alter the username max_length. You just have to run migrations i.e. python manage.py migrate auth to update your database tables.

Post a Comment for "Change Username Max_length In Django 1.11 (django.contrib.auth)"