CustomUser的南添加模型失败

时间:2014-01-13 21:31:37

标签: python django python-2.7 django-south django-users

我的项目使用django.contrib.auth.models.User。我想让email字段唯一,因此我定义了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']

但是当我运行manage.py schemamigration myapp --auto时,我收到此错误:

AttributeError: Manager isn't available; User has been swapped for 'myapp.models.CustomUser'

我做错了什么?

1 个答案:

答案 0 :(得分:0)

正如answer建议的那样,我必须在我的代码中的任何地方替换User我的新CustomUser。由于我忘了在我的django-rest-framework API代码中替换它,因此South在schemamigration命令期间引发了错误。