On Tue, Nov 17, 2009 at 7:15 PM, Continuation <selforgani...@gmail.com>wrote:
> I'm running a django project (actually a Pinax project) on the > development server. > > At my settings.py I made sure DEBUG = True > > Then I hit a few pages that for sure resulted in hitting the database. > > Then I did "python manage.py shell" to bring up the interactive > console. > > Next I tried to look at the raw SQl queries that were generated by > Django: > > In [2]: from django.db import connection > In [3]: connection.queries > Out[3]: [] > > Why is connection.queries empty? I tried this several times with the > same results. > > What have i missed? > > You can't access the connection.queries for the running server process by starting up an independent shell. The queries attribute is associated with a database connection -- the shell session you start makes its own connection to the database and will have its own independent connection.queries. Thus when you look at connection.queries from the shell, you see the queries that have been issued from the shell process. (Also, in fact a new database connection is established and torn down for each request processed by the server, so even the running server is not maintaining a complete list of queries for the life of the server -- it just maintains a list for the life of a particular connection, which generally only lasts the lifetime of an individual request.) If you want to see the queries needed to generate particular pages, probably the easiest way is to install django-debug-toolbar: http://robhudson.github.com/django-debug-toolbar/ Karen -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=.