开发者

Django with multiple database

I have a Django application with two configured databases first_DB and second_DB

The configurations seems as following

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'    : '',
    },
}

The nagios database is readonly and this is configured in the routers module.

开发者_如何学Go

The nagios database is on a remote machine

my application gets data from nagios DB and inserts it into my local DB

If the nagios machine is down, or mysql on nagios machine is turned off, the django server starts with the following error

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

and the application does not work

What I understand is that Django server tries to connect to all the configured databases

but I want to get my application working even if the second database is unreachable

How can I do that?


If you don't know where the 500 error is coming from, set DEBUG=True in your settings, and look at the debug stack trace page that is produced. It will show you where the exception is being raised.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜