Migrations bork: relation "django_site" does not exist

1,071 views
Skip to first unread message

Malte

unread,
Mar 9, 2016, 7:15:17 AM3/9/16
to Django users
Hi all,

I ran into this error trying to migrate my apps with a blank Postgres database.

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

LINE 1: ..."django_site"."domain", "django_site"."name" FROM "django_si...


The issue was raised by others (e.g. on SOF http://stackoverflow.com/questions/23925726/django-relation-django-site-does-not-exist) but not really solved.

I realised that I could work around this issue by 
Step 1: commenting out all of the apps that I custom built from (A) INSTALLED_APPS and (B) urls.py
Step 2: running .manage.py migrate
Step 3: commenting my apps back in
Step 4: running .manage.py migrate

But this doesn't seem right. None of the suggestions out there have worked for me, including: ./manage.py migrate sites (which results in the same error).
In fact, whatever migrate or makemigrations command I run, it all results in the "relation "django_site" does not exist" error.

So I came across this, where the last comms dates back less than 2 weeks with Simon Charette taking it to the irc channel.


Is there any follow-up from this?

Thanks!
/Malte

Michal Petrucha

unread,
Mar 9, 2016, 7:42:59 AM3/9/16
to django...@googlegroups.com
The symptoms described in the ticket do not match yours.

You wrote that you're getting the error even when running
makemigrations, whereas the reporter of that ticket wrote that
makemigrations succeeds, but a subsequent migrate fails.

From what you described, it seems like your project tries to perform a
database query on startup, which obviously will not work before you
actually create the database with an up-to-date schema. It's
impossible to tell with certainty without seeing the full traceback or
any code, but it looks like you are trying to fetch a Site object from
the database on startup (as in, one of your applications makes queries
on import time). This is simply not supported, because such an
operation does not make sense, when you think about it. (There's a
chicken-and-egg problem in this scenario.)

All in all, from your description is seems to me that there is nothing
Django can do about the issue, but you'll have to provide more
information in order for us to help you resolve the problem.

Cheers,

Michal
signature.asc
Reply all
Reply to author
Forward
0 new messages