How to Solve Error Message RuntimeError: Model class django.contrib.sites.models.Site doesn’t declare an explicit app_label and isn’t in an application in INSTALLED_APPS in Django Application

Posted on

Introduction

Another article showing about how to solve a certain error message appear upon executing a certain command. That command is for running a Django-based internal service. The Django-based internal service is running to accept any requests for requesting a certain page of the Django-based web application. In the title of this article, there is an error message in the short form :

RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

Furthermore, the error in the complete display after executing the command of ‘python manage.py runserver’. The execution as complete display is available as follows :

(env) C:\programming\python\django\myproject>python manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\app\python39\lib\threading.py", line 973, in _bootstrap_inner
self.run()
File "C:\app\python39\lib\threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "C:\app\python39\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\app\python39\lib\site-packages\django\core\management\commands\runserver.py", line 110, in inner_run
autoreload.raise_last_exception()
File "C:\app\python39\lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception
raise _exception[1]
File "C:\app\python39\lib\site-packages\django\core\management\__init__.py", line 375, in execute
autoreload.check_errors(django.setup)()
File "C:\app\python39\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\app\python39\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\app\python39\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\app\python39\lib\site-packages\django\apps\config.py", line 301, in import_models
self.models_module = import_module(models_module_name)
File "C:\app\python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\app\python39\lib\site-packages\django\contrib\flatpages\models.py", line 1, in <module>
from django.contrib.sites.models import Site
File "C:\app\python39\lib\site-packages\django\contrib\sites\models.py", line 78, in <module>
class Site(models.Model):
File "C:\app\python39\lib\site-packages\django\db\models\base.py", line 113, in __new__
raise RuntimeError(
RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

Solution

Then, as a solution to solve the above problem, just add one single line in the ‘settings.py’ file exist in the folder project of the Django-based framework. The following is that line of solving the error message :

'django.contrib.sites',

So, the content in a complete form will be exist as follows :

# Application definition
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'crispy_forms',
    'myproject',
    'mptt',
]

After that, just execute the Django-based internal service once more. If there are no more errors appear, the application will run properly.

One thought on “How to Solve Error Message RuntimeError: Model class django.contrib.sites.models.Site doesn’t declare an explicit app_label and isn’t in an application in INSTALLED_APPS in Django Application

Leave a Reply