Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

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...
                                                             ^


My website is an heroku app and has been deployed using git commands.

Please let me know if you need further details.

Thanks in advance!

What I have tried:

Many related issues were suggesting to perform a migration, which I did. This didn't work though.
Posted
Updated 23-Jan-20 9:49am
Comments
Kris Lantz 21-Jan-20 8:20am    
Just for clarity, is this an additional page being added to a site that is already live (and working otherwise?)
CuriousIT 21-Jan-20 8:28am    
Yes, my site was already live before I added the sitemap. The sitemap is normally generated when using a local server but for a reason I ignore doesn't work live. The rest of the website works as expected.
Kris Lantz 21-Jan-20 10:23am    
Were there any errors or status notifications when you ran the migrate?
CuriousIT 21-Jan-20 11:19am    
No, it looks good. I retried the 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 seems 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?
Fatima-Zahra Chriha 21-Jun-20 15:53pm    
I am facing the same issue

1 solution

Commenting out "'django.contrib.sites'," in the settings file solved the issue.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900