Trying to create my custom user model, this is the code I have:
models.py
class CustomUser(AbstractUser):
USERNAME_FIELD = 'email'
CustomUser._meta.get_field_by_name('email')[0]._unique=True
settings.py
AUTH_USER_MODEL = 'myapp.CustomUser'
When doing the manage.py syncdb, the following error occurs:
CommandError: One or more models did not validate:
myapp.customuser: The field named as the USERNAME_FIELD should not be included in REQUIRED_FIELDS on a swappable User model.
Can anyone shed some light? Is there a better way of customizing the user model in Django 1.6 without rewriting the entire class extending AbstractBaseUser?
Btw, if I delete USERNAME_FIELD = 'email' from my code and change the core django auth/models.py >> AbstractUser definition, it works. I just can't seem to be able to override the USERNAME_FIELD...
Thanks!