About SQL Query Inspection

When in DEBUG mode, you can inspect the latest executed SQL queries and their execution time with:

1
2
3
4
>>> from django.db import connection
>>> connection.queries
[{'sql': 'SELECT …', 'time': '0.001'}, 
{'sql': 'SELECT …', 'time': '0.004'}]

Tips and Tricks Development Databases Optimization Django 4.2 Django 3.2 Django 2.2