Django issue: relation "django_site" does not exist

curiousIT

I’ve been trying to add a sitemap to my django website lately. While it looked ok on the local server, when it went live it returned the following error:

relation "django_site" does not exist LINE 1: ..."django_site"."domain", "django_site"."name" FROM "django_si...

I’ve been trying many things, notably the migration tricks I saw elsewhere but it never worked (even though I might have done it wrong; I'm new to this and not much at ease). I also get the same error when I try to load the admin page.

For info, I’m using Python 3.7.5 and Django version is 2.2.5.

This is how my settings file looks like:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.sitemaps',
'myapp',]

SITE_ID = 1

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',]

And here is some more info about the errors:

Traceback:

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py" in _execute
  84.                 return self.cursor.execute(sql, params)

The above exception (relation "django_site" does not exist
LINE 1: ..."django_site"."domain", "django_site"."name" FROM "django_si...
                                                             ^
) was the direct cause of the following exception:

File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/sitemaps/views.py" in inner
  16.         response = func(request, *args, **kwargs)

File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/sitemaps/views.py" in sitemap
  53.     req_site = get_current_site(request)

File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/sites/shortcuts.py" in get_current_site
  13.         return Site.objects.get_current(request)

File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/sites/models.py" in get_current
  58.             return self._get_site_by_id(site_id)

File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/sites/models.py" in _get_site_by_id
  30.             site = self.get(pk=site_id)

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/manager.py" in manager_method
  82.                 return getattr(self.get_queryset(), name)(*args, **kwargs)

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/query.py" in get
  402.         num = len(clone)

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/query.py" in __len__
  256.         self._fetch_all()

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/query.py" in _fetch_all
  1242.             self._result_cache = list(self._iterable_class(self))

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/query.py" in __iter__
  55.         results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  1100.             cursor.execute(sql, params)

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py" in execute
  99.             return super().execute(sql, params)

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py" in execute
  67.         return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py" in _execute_with_wrappers
  76.         return executor(sql, params, many, context)

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py" in _execute
  84.                 return self.cursor.execute(sql, params)

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/utils.py" in __exit__
  89.                 raise dj_exc_value.with_traceback(traceback) from exc_value

File "/app/.heroku/python/lib/python3.7/site-packages/django/db/backends/utils.py" in _execute
  84.                 return self.cursor.execute(sql, params)

Exception Type: ProgrammingError at /sitemap.xml
Exception Value: relation "django_site" does not exist
LINE 1: ..."django_site"."domain", "django_site"."name" FROM "django_si...
                                                             ^

Also, I retried performing a migration just in case (so deleted the pycache folder in my migrations folder, dropped the database and then ran a new migration using command line: python manage.py migrate). Everything seemed ok. Nevertheless I must add that my migrations folder is mostly empty. I just have the init.py file and the pycache folder which only contains a file named init.cpython-37.pyc. Is this normal?

Please let me know if you need further details.

Thanks in advance!

curiousIT

OK, so I managed to find the cause of the issue. I thought I already done it but obviously no. I came across a similar problem where one had to only comment out "'django.contrib.sites'," in the settings file. Doing this allowed both the sitemap and admin pages to get loaded.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Django error: relation "users_user" does not exist

relation "account_emailaddress" does not exist - django error

Django column "name" of relation "django_content_type" does not exist

No such table as django_site

Must be owner of relation django_site when manage.py migrate

ProgrammingError: relation "django_site" does not exist

Django + posgtres relation does not exist error

Django: relation "django_site" does not exist in app with psql using sites framework

Django 1.8 test issue: ProgrammingError: relation "auth_user" does not exist

ProgrammingError: relation "django_session" does not exist

Relation does not exist in django admin site after migrations

Relation does not exist - Django & Postgres

Django no such table: django_site after deleting migrations and database

Python Django - Internal Error ProgrammingError relation does not exist

django.db.utils.ProgrammingError: relation "..." does not exist

Django DatabaseError: relation "django_site"

Relation *tablename* does not exist

OperationalError at : "site" Exception Value: No such Table django_site

Django: Relation does not exist in Postgresql

relation "old" does not exist

Django migrations: relation does not exist

Django: relation does not exist

Relation does not exist PLPGSQL

executing raw sql in django error: relation does not exist

relation "blog_blog" does not exist - error in Django app

django.db.utils.ProgrammingError: relation does not exist with recursive model

Relation does not exist error in Django after postgresql integration

Relation does not Exist/ Programming Error in django

I tried updating django_site row to change the name but I have gotten ERROR: column "alt native" does not exist