Question

I'm getting this error message on my email field but i'm using the built in django auth system. Is there an easy way to override it. When the user registers the email address is added into the built in field within the built in user system.

Would be great if it's possible to make it extend it over 30 chars due to the nature of the site.

Was it helpful?

Solution

That is one of the issues with using email addresses for user names in Django. Many, many emails are over 30-characters. One common way to address this issues is using a custom "Authentication Backend" for email authentication. Using your own backend you can authenticate a user based on the email field instead of the username field. You can then generate the username based on that email address or using random generated usernames.

You can read more about this approach on my blog post Django Authentication using an Email Address.

OTHER TIPS

Maybe it is not right way, but in my project i just increased user email size with south. Sample:

    >> ./manage.py schemamigration auth --initial && ./manage migrate auth --fake

Then i added into models.py:

    from django.contrib.auth.models import User
    field = User._meta.get_field('email')
    field.max_length = 254
    field = User._meta.get_field('username')
    field.max_length = 254

Now:

    >> ./manage.py schemamigration auth --auto
    >> ./manage.py migrate auth
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top