Alternative for django.db.close_connection()

2019-07-17 05:35发布

问题:

Is there a possible way to re-establish MySQL connection in Django after it goes down?

I am getting the following error while trying to access MySQL using the get_wsgi_application in django.core.wsgi:

(2006,'MYSQL server has gone away')

回答1:

We need to close the old connection to db, which Django had automatically created before.

We can do this by executing the function:

django.db.close_old_connections()

Django automatically creates new connections after closing previous connections.