solution for python django.db.utils.InterfaceError: (0, '')

created at 07-15-2021 views: 45

error message

django.db.utils.InterfaceError: (0, '')

Reasons for database disconnection

Because the default wait_timeout=28800 of the database, the unit is second (s), it is 8 hours when converted to hours (it is related to the mysql setting information). That is, once my service is started, it will be automatically disconnected by mysql after 8 hours.


This is caused by the global cursor. Try to create and close the cursor within each method, which requires the original query.


cursor = connection.cursor()

Or use with:

with connections.cursor() as cursor:
created at:07-15-2021
edited at: 07-15-2021: