How can you get the SQL for a Django model’s .save(), i.e.
from django.db import models
class MyM(models.Model):
text = models.TextField()
How can you get the SQL that would be created/used in the following scenario:
>>> m = MyM(text="123")
>>> m.save()
# What SQL Django just run?
Thanks!
From the Django FAQ:
How can I see the raw SQL queries Django is running?
Make sure your Django DEBUG setting is set to True. Then, just do this:
db.queries is only available if DEBUG is True. It’s a list of dictionaries in order of query execution. Each dictionary has the following:
sql–The raw SQL statementtime— How long the statement took to execute, in seconds.db.queries includes all SQL statements — INSERTs, UPDATES, SELECTs, etc.