Django DatabaseError: relation "django_site"
Asked Answered
R

10

11

I currently have a django app am developing on my PC with data in my db but when i try running this app on a test server i get the error below

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

can any one tell me why am getting this error please.thanks

Ripply answered 26/7, 2013 at 21:40 Comment(3)
Did you sync the database on the test server?Alcheringa
yes i did syncd the be and thats when i get that error i also tried running manage.py runserver and still the error is still sameRipply
Did you alter or not include the SITE_ID setting in settings.py such that the SITE_ID doesn't correlate to a record in the django_site table?Alcheringa
R
2

not been able to solve this a django way so i tried using sql, i created a dump of just the database like this.

pg_dump mypgdatabase | gzip -c > mypgdatabase.dump.out.gz

then moved it to the server

scp /path/to/mypgdatabase.dump.out.gz  my_remote_server

then recreated it on the server like this

psql -d mypgdatabase -f mypgdatabase.dump.out

then run

./manange.py migrate --all

and all when well.

Ripply answered 27/7, 2013 at 13:0 Comment(0)
E
8

You may be calling a site object before creating site model(before syncdb)

ex: site = Site.objects.get(id=settings.SITE_ID)

Elliott answered 11/8, 2014 at 7:10 Comment(0)
B
5

This issue continues to plague many, including myself. Although a tedious process, this approach saves me the brain power:

Disable all external apps in your INSTALLED_APPS, except your own apps, like so:

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.flatpages',
    'main', # This is my own app.

    # 'compressor',
    # 'ckeditor',
    # 'imagekit',
    # 'debug_toolbar',
    # 'rest_framework',
    # 'allauth',
    # 'allauth.account',
    # 'allauth.socialaccount',

    # 'allauth.socialaccount.providers.google',
    # 'allauth.socialaccount.providers.facebook',
)

Run

python manage.py makemigrations
python manage.py migrate

Then, uncomment all the other apps, then repeat makemigrations and migrate above.

That works all the time for me

Barranca answered 16/6, 2015 at 23:57 Comment(0)
H
4

I can't see your models or what apps are you using, but my guess is that you are using django_site (Site model) and you don't have 'django.contrib.sites' in the INSTALLED_APPS.

If I'm correct then just add 'django.contrib.sites', to your INSTALLED_APPS.

Haemato answered 27/7, 2013 at 0:33 Comment(1)
i have django.contrib.sites installedRipply
V
4

Had this strange issue while initiating a new database and using django-debug-toolbar. Removed it from the INSTALLED_APPS and was able to run syncdb. Then re-added debug_toolbar and it was still working fine.

If you're using django-debug-toolbar, try to comment out debug_toolbar in your installed apps and try again.


Update: Please follow the steps for the explicit setup: http://django-debug-toolbar.readthedocs.org/en/1.2.2/installation.html#explicit-setup

Vallery answered 14/3, 2014 at 10:48 Comment(1)
Tried this, didn't work. I'm on django 1.8 and using postgresqlBarranca
S
3

i have same problem and fixed it like this:

  1. add SITE_ID=1 into settings.py
  2. run this command :

    python manage.py migrate

Strop answered 23/4, 2015 at 15:55 Comment(0)
R
2

not been able to solve this a django way so i tried using sql, i created a dump of just the database like this.

pg_dump mypgdatabase | gzip -c > mypgdatabase.dump.out.gz

then moved it to the server

scp /path/to/mypgdatabase.dump.out.gz  my_remote_server

then recreated it on the server like this

psql -d mypgdatabase -f mypgdatabase.dump.out

then run

./manange.py migrate --all

and all when well.

Ripply answered 27/7, 2013 at 13:0 Comment(0)
C
1

Couple of things you can try and check:

  • Your settings.py should have a SITE_ID usually = 1
  • Change order of your INSTALLED_APPS in your settings.py and try temporarily commenting items out.
  • As Geo said, check that you're not calling a site object before creating site model (ex: site = Site.objects.get(id=settings.SITE_ID)).

Once you got it working, remember to manage.py makemigrations APP_NAME as I found cases where it seem to have then avoided the commenting out step.

Canaan answered 2/3, 2016 at 22:35 Comment(0)
C
0

I overcame this issue with the following order in INSTALLED_APPS:

INSTALLED_APPS = (
    'django.contrib.sites',
    'allauth',                                                                 
    'allauth.account',                                                         
    # my other apps,
)
Collins answered 18/4, 2016 at 19:23 Comment(0)
R
0

My "commenting out" pattern was slightly different than the accepted answers (as shown below). That is to say, it might be unique depending on the values of various dependencies scattered throughout your app. If commenting out the values above throws an error message, I recommend commenting out the apps that throw the error message and uncommenting accordingly until it works for you. This may be a little "brute force" but it should get the job done.

INSTALLED_APPS = [
    # django native apps
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    "django.forms",
    'django.contrib.gis',
    # 'django.contrib.flatpages',
    #third party apps
    #django-allauth apps
    'allauth',
    # 'allauth.account',
    # 'allauth.socialaccount',
    # 'allauth.socialaccount.providers.facebook',
    # 'allauth.socialaccount.providers.google',
    # 'allauth.socialaccount.providers.twitter',
    # 'allauth.socialaccount.providers.github',
    # my apps
    'app0',
    'app1',]

#MIGRATION_MODULES = {"sites": "mysite.contrib.sites.migrations"}
Rooseveltroost answered 9/10, 2020 at 17:25 Comment(0)
I
-2

Also make sure SITE_ID = 1 comes before the DATABASE definition in settings.py

Igor answered 27/7, 2015 at 19:35 Comment(1)
I don't see how that could affect anything. DATABASES and SITE_ID are both variable that get assigned to strings, and those settings are loaded by Django, no matter the order it'll have no effect at all (quite unlike the order of the apps in the list).Canaan

© 2022 - 2024 — McMap. All rights reserved.