Opened 11 years ago

Closed 11 years ago

#20097 closed Cleanup/optimization (invalid)

The field named as the USERNAME_FIELD should not be included in REQUIRED_FIELDS on a swappable User model.

Reported by: Alper Cugun Owned by: nobody
Component: contrib.auth Version: 1.5
Severity: Normal Keywords:
Cc: bmispelon@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I've created a User model that subclasses AbstractBaseUser and contains just this:

USERNAME_FIELD = 'email'

If I try to use that django gives this error:
"The field named as the USERNAME_FIELD should not be included in REQUIRED_FIELDS on a swappable User model."

Which I can't figure out because I haven't put anything in REQUIRED_FIELDS.

Change History (1)

comment:1 by Baptiste Mispelon, 11 years ago

Cc: bmispelon@… added
Resolution: invalid
Status: newclosed

Hi,

AbstractBaseUser does not have an email` field so the following is invalid:

class MyCustomUser(AbstractBaseUser):
    USERNAME_FIELD = 'email'

This will raise the following error: MyCustomUser has no field named 'email'

Now, if you subclass AbstractUser instead in the same fashion, then you get the error message you indicated.

The reason for this is that AbstractUser defines REQUIRED_FIELDS = ['email'], hence the error message.

Note: See TracTickets for help on using tickets.
Back to Top