How can I get a request for .save () in django?

I am updating a django model object. After setting the value for each attribute, when I call obj.save(), it gives me OperationalError: (2006, 'MySQL server has gone away'). I desperately want to know what causes the following error. How can I get a request? Since when trying to save the method due to the error above, it does not register the request. Any suggestions ?? Thanks in advance.

+5
source share
1 answer

You can try

from django.db import connection
connection.queries

it will provide you with a list of all requests that are executed through Django (including .save ()). To get your request, you can do

try:
    modelObj.save()
except OperationalError:
    from django.db import connection
    print connection.queries[-1]
+9
source

All Articles