I\'m at wit\'s end. After a dozen hours of troubleshooting, probably more, I thought I was finally in business, but then I got:
Model class django.contrib.co
I got this error today and ended up here after googling. None of the existing answers seem relevant to my situation. The only thing I needed to do was to import a model from my __init__.py
file in the top level of an app. I had to move my imports into the functions using the model.
Django seems to have some weird code that can fail like this in so many different scenarios!
I ran into this error when I tried generating migrations for a single app which had existing malformed migrations due to a git merge. e.g.
manage.py makemigrations myapp
When I deleted it's migrations and then ran:
manage.py makemigrations
the error did not occur and the migrations generated successfully.
in my case I was able to find a fix and by looking at the everyone else's code it may be the same issue.. I simply just had to add 'django.contrib.sites' to the list of installed apps in the settings.py file.
hope this helps someone. this is my first contribution to the coding community
I got this error also today. The Message referenced to some specific app of my apps in INSTALLED_APPS. But in fact it had nothing to do with this specific App. I used a new virtual Environment and forgot to install some Libraries, that i used in this project. After i installed the additional Libraries, it worked.
I get the same error and I don´t know how to figure out this problem. It took me many hours to notice that I have a init.py at the same direcory as the manage.py from django.
Before:
|-- myproject
|-- __init__.py
|-- manage.py
|-- myproject
|-- ...
|-- app1
|-- models.py
|-- app2
|-- models.py
After:
|-- myproject
|-- manage.py
|-- myproject
|-- ...
|-- app1
|-- models.py
|-- app2
|-- models.py
It is quite confused that you get this "doesn't declare an explicit app_label" error. But deleting this init file solved my problem.
I received this error after I moved the SECRET_KEY
to pull from an environment variable and forgot to set it when running the application. If you have something like this in your settings.py
SECRET_KEY = os.getenv('SECRET_KEY')
then make sure you are actually setting the environment variable.