Django model “doesn't declare an explicit app_label”

后端 未结 28 1765
無奈伤痛
無奈伤痛 2020-11-27 15:38

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         


        
相关标签:
28条回答
  • 2020-11-27 16:09

    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!

    0 讨论(0)
  • 2020-11-27 16:10

    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.

    0 讨论(0)
  • 2020-11-27 16:10

    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

    0 讨论(0)
  • 2020-11-27 16:11

    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.

    0 讨论(0)
  • 2020-11-27 16:14

    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.

    0 讨论(0)
  • 2020-11-27 16:14

    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.

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