【问题标题】:Django with multiple database具有多个数据库的 Django
【发布时间】:2010-09-26 08:51:08
【问题描述】:

我有一个 Django 应用程序,其中包含两个已配置的数据库 first_DB 和 second_DB

配置如下

DATABASES = {
    'default': {
        'ENGINE'  : 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME'    : 'emonitor',                      # Or path to database file if using sqlite3.
        'USER'    : 'emonitor',                      # Not used with sqlite3.
        'PASSWORD': 'emonitor',                  # Not used with sqlite3.
        'HOST'    : '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT'    : '',                      # Set to empty string for default. Not used with sqlite3.
    },
    'nagios': {
        'ENGINE'  : 'django.db.backends.mysql',
        'NAME'    : 'nagios',
        'USER'    : 'emonitor',
        'PASSWORD': 'emonitor',
        'HOST'    : 'nagios.edc', 
        'PORT'    : '',
    },
}

nagios 数据库是只读的,这是在路由器模块中配置的。

nagios 数据库在远程机器上

我的应用程序从 nagios 数据库中获取数据并将其插入到我的本地数据库中

如果nagios机器宕机,或者nagios机器上的mysql关闭,django服务器启动出现如下错误

enter code here_mysql_exceptions.OperationalError: (2005, "Unknown MySQL server host 'nagios.edc' (1)")

应用程序不工作

我的理解是 Django 服务器尝试连接到所有已配置的数据库

但即使第二个数据库无法访问,我也想让我的应用程序正常工作

我该怎么做?

【问题讨论】:

    标签: python django


    【解决方案1】:

    如果您不知道 500 错误来自何处,请在设置中设置 DEBUG=True,然后查看生成的调试堆栈跟踪页面。它将向您显示引发异常的位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-13
      • 2023-03-23
      • 2012-07-07
      • 2016-09-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多