My project uses django.contrib.auth.models.User
. I want to make email
field unique, so I have defined CustomUser
:
class CustomUser(AbstractBaseUser):
username = models.CharField(_('username'), max_length=30, unique=True)
email = models.EmailField(_('Email'), max_length=254, unique=True)
first_name = models.CharField(_('first name'), max_length=30, blank=True)
last_name = models.CharField(_('last name'), max_length=30, blank=True)
is_staff = models.BooleanField(_('staff status'), default=False)
is_active = models.BooleanField(_('active'), default=True)
date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email']
But when I run manage.py schemamigration myapp --auto
, I get this error:
AttributeError: Manager isn't available; User has been swapped for 'myapp.models.CustomUser'
What have I done wrong?
As the answer suggests, I had to replace User
with my new CustomUser
everywhere in my code. Since I forgot to replace it in my django-rest-framework API code, South raised the error during schemamigration
command.