2

I'm using django's AbstractUser to create my custom user along with my custom manager that extends BaseUserManager. But I didn't add any extra fields to it yet. So it looks like this:

# mypoject/apps/accounts/models.py

from django.contrib.auth.models import AbstractUser
from myproject.apps.accounts.managers import UserManager

class User(AbstractUser):
    objects = UserManager

And I wrote a unit test for it, and it looks like this:

# myproject/apps/accounts/tests/test_models.py

from unittest import TestCase

class UserTests(TestCase):
    def test_create_user(self):
        from myproject.apps.accounts.models import User
        user = User.objects.create_user(username='mock_user')
        self.assertIsInstance(user)

But when I run the test, I get this error message:

RuntimeError: Model class myproject.apps.accounts.models.User doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

PS: My accounts app is in INSTALLED_APPS array and works fine.

  • Exactly what is in INSTALLED_APPS? And what is AUTH_USER_MODEL set to? – Daniel Roseman Aug 11 '16 at 12:59
  • My accounts app which contains the custom user model, is added to INSTALLED_APPS. And AUTH_USER_MODEL is set to 'accounts.User'. I even get `` for `get_user_model()`. The problem only occurs when I explicitly import my custom User model. @Daniel – Arian Rahimi Aug 12 '16 at 08:18

1 Answers1

1

This might be because of the issue described here and to the objects you need to assign manager instance

class User(AbstractUser):
    objects = UserManager()
Community
  • 1
  • 1
Arun Ghosh
  • 7,634
  • 1
  • 26
  • 38