35

When django-registration doesn't support django 1.5 and custom user model. I'm trying use django-allauth, from first look it's great product.

Problem i have - username field required, but in my app i don't have username's. So, allauth documentation says:

**Available settings:**
ACCOUNT_AUTHENTICATION_METHOD (="username" | "email" | "username_email")

Specifies the login method to use -- whether the user logs in by entering his username, e-mail address, or either one of both.

Ok, i done, and got error:

AssertionError at /accounts/signup/
No exception supplied

models.py:

class MyUser(AbstractBaseUser, PermissionsMixin):
    title = models.CharField ('Name', max_length=100)
    email = models.EmailField('Email', max_length=255, unique=True)
    ...

settings.py

ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = ('email')
AUTH_USER_MODEL = 'internboard.MyUser'

What i'm doing wrong ?

3 Answers 3

61

Thanks, i found, right settings for my task:

ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_USERNAME_REQUIRED = False
3
  • 2
    Hi Rukomoynikov, did you have to make your own user model for this to work? If so, what did it look like exactly (if you are willing to share) ?
    – ademartini
    Nov 17, 2014 at 14:46
  • 1
    More recent resource from official doc. django-allauth.readthedocs.org/en/latest/…
    – attomos
    Apr 23, 2015 at 6:03
  • The only problem with this is that if the user signs up with say facebook they don't have a user name in the Django user account.
    – SudoKid
    Jul 7, 2016 at 17:07
49

If you encounter the error django.core.exceptions.FieldDoesNotExist: Account has no field named 'username' with reference to USER_MODEL_USERNAME_FIELD in the stacktrace, you'll also need to set ACCOUNT_USER_MODEL_USERNAME_FIELD to None (or the appropriate field for your use case). The full set of settings needed are the following:

ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_USERNAME_REQUIRED = False

This setting is explained in more detail in the django-allauth documentation for Custom User Models with defaults outlined in Configuration.

1
  • 1
    thanks a lot, this fix the FieldDoesNotExist error
    – Phifo
    Sep 2, 2021 at 22:30
2

A probable cause could be any of the following for a custom user model;

a) if you've totally eliminated "Username" as a field in your model, then, do ensure that in your model, you define the variable:

               USERNAME_FIELD = 'email'

Also, do ensure that in the field definition of email, the field attribute;

              unique = True

is as well included.

b) In your custom User admin (which must be compulsorily configured), the form and add_form variables must be defined to inherit from "ModelForm" or UserCreationForm (for the add_form variable).

c) if you're inheriting allauth's Signup Form, then, you'll have to declare in your settings:

 ACCOUNT_USER_MODEL_USERNAME_FILED = None

Most importantly, ensure you write tests to ensure that form posts data and saves to the database. Thanks. Hope someone finds this helpful..... Remember, it can only be hard, but never impossible!!! Happy 'Djangoing'....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.