def check_database_connected(app_configs, **kwargs):
"""
A Django check to see if connecting to the configured default
database backend succeeds.
"""
errors = []
try:
connection.ensure_connection()
except OperationalError as e:
msg = 'Could not connect to database: {!s}'.format(e)
errors.append(checks.Error(msg, id=ERROR_CANNOT_CONNECT_DATABASE))
except ImproperlyConfigured as e:
msg = 'Datbase misconfigured: "{!s}"'.format(e)
errors.append(checks.Error(msg, id=ERROR_MISCONFIGURED_DATABASE))
else:
if not connection.is_usable():
errors.append(checks.Error('Database connection is not usable',
id=ERROR_UNUSABLE_DATABASE))
return errors
评论列表
文章目录