Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How can I see the raw SQL queries Django is running?

django queries raw running sql
0
Posted

How can I see the raw SQL queries Django is running?

0

446 —————————————————- 447 448 Make sure your Django “DEBUG“ setting is set to “True“. Then, just do 449 this:: 450 451 >>> from django.db import connection 452 >>> connection.queries 453 [{‘sql’: ‘SELECT polls_polls.id,polls_polls.question,polls_polls.pub_date FROM polls_polls’, 454 ‘time’: ‘0.002’}] 455 456 “connection.queries“ is only available if “DEBUG“ is “True“. It’s a list 457 of dictionaries in order of query execution. Each dictionary has the following:: 458 459 “sql“ — The raw SQL statement 460 “time“ — How long the statement took to execute, in seconds. 461 462 “connection.queries“ includes all SQL statements — INSERTs, UPDATES, 463 SELECTs, etc. Each time your app hits the database, the query will be recorded.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.