Django Model "Doesn't Declare an Explicit App_Label"

Django model doesn't declare an explicit app_label

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'

RuntimeError: Model class xxx doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS

Working with absolute imports in the view solved my issue. I changed .models to apfelschuss.votes.models.

Code that leads to runtime error:

from django.shortcuts import render

from .models import Voting

Issue solved with absolute import:

from django.shortcuts import render

from apfelschuss.votes.models import Voting

See commit on GitHub here.

RuntimeError: Model class myapp.models.class doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS

Your INSTALLED_APPS list in django_proj\settings.py is incorrect. Each item in the list should be separated with commas. Try updating your list like below.

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
# My App
'polls',
'pages',]


Related Topics



Leave a reply



Submit