Guidebook Engineering Blog Nov 19, 2015 1 minute read
Django: Super debugsqlshell Shell
When you’re nearing the expressive limit of the Django ORM, it’s often useful to open up a python shell and see exactly what SQL Django is generating for you.
django-debug-toolbar includes the
debugsqlshell command for printing out the SQL run in the django ORM – making SQL exploration easy.
debugsqlshell can be a little plain, though – we’ve grown used to the
shell_plus command from
django_extensions for automatically importing all our models and tools.
For the best of both worlds, we put the two shells together in a third management command that imports all your django models and prints any SQL you run via the Django ORM:
Note that the following two packages are required to run the above management command:
I’ve used explicit version numbers because the above command is not part of the public APIs of
django-extensions – the code is subject to change as the respective packages evolve.