Django model "doesn't declare an explicit app_label"
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Techno Intrigue Looping
--
Chapters
00:00 Django Model &Quot;Doesn'T Declare An Explicit App_label&Quot;
00:54 Accepted Answer Score 171
01:38 Answer 2 Score 28
02:20 Answer 3 Score 41
02:36 Answer 4 Score 59
03:03 Thank you
--
Full question
https://stackoverflow.com/questions/4020...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #django #python3x
#avk47
ACCEPTED ANSWER
Score 171
Are you missing putting in your application name into the settings file?
The myAppNameConfig is the default class generated at apps.py by the .manage.py createapp myAppName command. Where myAppName is the name of your app.
settings.py
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 apps.py file by adding the following code in
myAppName/apps.py
class myAppNameConfig(AppConfig):
    name = 'myAppName'
    verbose_name = 'A Much Better Name'
ANSWER 2
Score 59
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 manage.py.
ANSWER 3
Score 41
I got this one when I used ./manage.py 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()
ANSWER 4
Score 28
as a noob using Python3 ,I find it might be an import error instead of a Django error
wrong:
from someModule import someClass
right:
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 this.here's what I remember:
try to register a model in admin.py:
from django.contrib import admin
from user import User
admin.site.register(User)
try to run server, error looks like this
some lines...
File "/path/to/admin.py" ,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