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
Python Ungzipping Stream of Bytes
How to Remove Duplicates from a CSV File
Go to a Specific Line in Python
Sqlite3, Operationalerror: Unable to Open Database File
Overwriting File in Ziparchive
Is There a Recursive Version of the Dict.Get() Built-In
Python Time + Timedelta Equivalent
Check for Identical Rows in Different Numpy Arrays
How to Control the Mouse in MAC Using Python
What Does "\R" Do in the Following Script
How to Install a Python Package from Within Ipython
Use of True, False, and None as Return Values in Python Functions
Python Django Global Variables
Finding First and Last Index of Some Value in a List in Python
Find the Division Remainder of a Number
Selenium Unable to Locate Element Only When Using Headless Chrome (Python)