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])