AUTH_USER_MODEL refers to model .. that has not been installed and created AbstractUser models not able to login

前端 未结 4 755
盖世英雄少女心
盖世英雄少女心 2020-12-15 03:43

AUTH_USER_MODEL error solved in EDIT3. Passwords still will not save on user creation via form.

I\'m using Django 1.5 playing around wi

4条回答
  •  爱一瞬间的悲伤
    2020-12-15 04:14

    I've run into this a few times. It's always been an import issue. Suppose we have core/models.py that implements a custom user and imports a symbol from another file (say Else):

    from Something import Else
    
    class CustomUser(AbstractBaseUser):
        pass
    

    And then we have another file that uses CustomUser and also defines Else. Let's call this something/models.py:

    from core.models import CustomUser
    
    class Else(models.Model):
        pass
    
    class AnotherClass(models.model):
        user = models.ForeignKey(CustomUser)
    

    When core/models.py goes to import Else, it evaluates something/models.py and runs into the AnotherClass definition. AnotherClass uses CustomUser, but CustomUser hasn't been installed yet because we're in the process of creating it. So, it throws this error.

    I've solved this problem by keeping my core/models.py standalone. It doesn't import much from my other apps.

提交回复
热议问题