I am updating a django model object. After setting value for each attribute when i call obj.save()
it gaves me OperationalError: (2006, 'MySQL server has gone away')
. I am desperate to know what is causing the following error. How can i get the the query?? As when save method fail because of above error it does not log query.
Any suggestions?? Thanks in advance.
You can try
from django.db import connection
connection.queries
it will give you list of all the queries that executed through Django (including .save()). To get your query you can do,
from django.db import connection, OperationalError
try:
modelObj.save()
except OperationalError:
print(connection.queries[-1])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With