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!
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.
Comments