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.