我能想到的选项:
cron定期检查失败的数据库连接的作业,并在发现此类失败时更新设置。要检查连接,您可以使用该方法django.db.connection.ensure_connection()。如果你看看这个答案,你可以尝试这样的事情:
from django.db import connection
from django.db.utils import OperationalError
class Command(BaseCommand):
def handle(self, *args, **options):
try:
# if this succeeds, no further action is needed
connection.ensure_connection()
except OperationalError:
# update the DB password and try again
Run Code Online (Sandbox Code Playgroud)