python - Django model "doesn't declare an explicit app_label"

ID : 20137

viewed : 18

Tags : pythondjangopython-3.xpython

Top 5 Answer for python - Django model "doesn't declare an explicit app_label"

vote vote


Are you missing putting in your application name into the settings file? The myAppNameConfig is the default class generated at by the createapp myAppName command. Where myAppName is the name of your app.

INSTALLED_APPS = [ 'myAppName.apps.myAppNameConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ] 

This way, the settings file finds out what you want to call your application. You can change how it looks later in the file by adding the following code in


class myAppNameConfig(AppConfig):     name = 'myAppName'     verbose_name = 'A Much Better Name' 
vote vote


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 at the same direcory as the from django.


|-- myproject   |--  <---   |--   |-- myproject     |-- ...   |-- app1     |--   |-- app2     |-- 


|-- myproject   |--   |-- myproject     |-- ...   |-- app1     |--   |-- app2     |-- 

It is quite confused that you get this "doesn't declare an explicit app_label" error. But deleting this init file solved my problem.

vote vote


I had exactly the same error when running tests with PyCharm. I've fixed it by explicitly setting DJANGO_SETTINGS_MODULE environment variable. If you're using PyCharm, just hit Edit Configurations button and choose Environment Variables.

Set the variable to your_project_name.settings and that should fix the thing.

It seems like this error occurs, because PyCharm runs tests with its own

vote vote


I got this one when I used ./ shell then I accidentally imported from the root project level directory

# don't do this from project.someapp.someModule import something_using_a_model # do this from someapp.someModule import something_using_a_model  something_using_a_model() 
vote vote


as a noob using Python3 ,I find it might be an import error instead of a Django error


from someModule import someClass 


from .someModule import someClass 

this happens a few days ago but I really can't reproduce it...I think only people new to Django may encounter's what I remember:

try to register a model in

from django.contrib import admin from user import User 

try to run server, error looks like this

some lines... File "/path/to/" ,line 6 tell you there is an import error some lines... Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label 

change user to .user ,problem solved

Top 3 video Explaining python - Django model "doesn't declare an explicit app_label"