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

前端 未结 4 757
盖世英雄少女心
盖世英雄少女心 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:03

    In my case updating, proper app_label in meta solved this issue

    class APPUser(AbstractUser):
       password = models.TextField(blank=True)
    
       class Meta:
         app_label = 'app_auth'
         db_table = "app_user"
    
    0 讨论(0)
  • 2020-12-15 04:06

    It can happen if you forget to register your app in settings. In your settings.py file add the name of your app in the list of INSTALLED_APPS. I hope this helps.

    For instance, if your app name is 'users' it would look like this:

    INSTALLED_APPS = [
      ......
    
      'users'
    ]
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-15 04:15

    Ok there were three issues here for me, so I'm going to address all of them since I am pretty sure the first two will come up for someone else.

    • Manager isn't available; User has been swapped for 'poker.PokerUser'

    This was due to using but not recreating the UserCreationForm. When using custom models in 1.5, some model forms are available out of the box but this one must be recreated. See here for the docs.

    • The Manager isn't available; User has been swapped for 'poker.PokerUser'

    While I had AUTH_USER_MODEL = 'poker.PokerUser' set in my settings.py, I was calling get_user_model() from the poker.models location. You must call get_user_model() from a different location. Moving my form to registration.forms and calling get_user_model() from there worked correctly.

    • New users not saving

    This was just a brain fart on my end. In my UserRegistration model I was manipulating various fields from the form. When I passed those fields back to UserCreationForm for the save() method, I was not passing the password fields with it. Woops!

    0 讨论(0)
提交回复
热议问题