2👍
In debug mode, you could use django-debug-toolbar, it prints all SQLs executed, as well as callees and explains of the SQLs, and extra info such as templates invoking, request, signals, etc. Very handy indeed.
In shell, as Yuji Tomita suggests, print queryset.query
(in legacy Django it’s something like queryset._get_sql_clause()
, just FYI) or connection.queries
in your question.
👤okm
Source:stackexchange.com