This article brings you a tutorial on how to automatically reconnect the Django database. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Django database connection exceeds wait_timeout and the database is automatically reconnected when the connection is lost
https://github.com/zhanghaofe...
Installation
pip install django_db_reconnect
Note that only pymysql is supported. To use pymysql with Django, you need to install the package first and add the following code to __init__.py in the directory where settings.py is located:
import pymysql pymysql.install_as_MySQLdb()
Use
Add django_db_reconnect to INSTALLED_APPS in settings.py
INSTALLED_APPS = ( # 省略其他配置 'django_db_reconnect', )
Other issues
Transactions or other autocommit=False non-automatic submission situations will not automatically occur Reconnect, otherwise it may cause the writes before the connection is lost to be discarded without commit
The above is the detailed content of Tutorial on how to automatically reconnect the Django database. For more information, please follow other related articles on the PHP Chinese website!