Saturday, October 19, 2013

Site matching query does not exist. Lookup parameters were {'pk': 1}

Django 1.5.1

I created sample app and run the syncdb (python manage.py syncdb) and it created default tables for the application. It didn't created the tables for the app's model. For that I had to run -

python manage.py syncdb --all

It took care of the other tables creation.

Though while accessing the app I run into following error -

Traceback (most recent call last):
  File "/Users/Jaimin/Apps/Github/kqotes/quote/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in get_response
    response = middleware_method(request, response)
  File "/Users/Jaimin/Apps/Github/kqotes/quote/lib/python2.7/site-packages/django/contrib/redirects/middleware.py", line 23, in process_response
..................
  File "/Users/Jaimin/Apps/Github/kqotes/quote/lib/python2.7/site-packages/django/db/models/query.py", line 389, in get
    (self.model._meta.object_name, kwargs))
DoesNotExist: Site matching query does not exist. Lookup parameters were {'pk': 1}
Internal Server Error: /api-auth/login/

Tried different things, though couldn't figure anything.

Solution - After deleting the schema, I run python manage.py syncdb --all

bingo! All worked fine, and magically error is gone.

The issue was first time it didn't created entry for the app in site table (Its part of default tables when you do syncdb.)

select * from django_site

You can add manual entry, or drop the schema and run it again. That will assign the primary key object and app will come up fine.

Any other comments, observation, feel free to drop in comment.

No comments:

Post a Comment