Home > Database > Mysql Tutorial > body text

Tutorial on how to automatically reconnect the Django database

不言
Release: 2019-02-21 11:44:32
forward
2834 people have browsed it

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
Copy after login

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()
Copy after login

Use

Add django_db_reconnect to INSTALLED_APPS in settings.py

INSTALLED_APPS = (
    # 省略其他配置
    'django_db_reconnect',
)
Copy after login

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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!