简体   繁体   中英

Django Project Multi-Database Config in settings.py

I am currently in the process of taking an asp.NET internal website written in C# and redoing it in the Django web framework. After identifying all of the current data sources being used by the .NET site, I have begun configuring and testing my ability to connect to those databases from within the Django framework.

  • Platform: Archlinux
  • Django Version: 1.3.1
  • Python Version: 2.7

Problem: Whenever I try to connect to any database that is not defined as the default database, I am unable to do so. Furthermore, any database that I am unable to connect to, is only when it is defined as not being the default.

To further illustrate this point, I will provide redacted examples:

DATABASES = {
    'default': {
        'ENGINE': 'postgresql_psycopg2',
        'NAME': 'postgres',
        'USER': 'postgres',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
    },
    'mssql': {
        'ENGINE': 'sql_server.pyodbc',
        'DATABASE_ODBC_DSN': 'name_of_sql_server',
        'DATABASE_NAME': 'Logs',
        'DATABASE_USER': r'user_name',
        'DATABASE_PASSWORD': 'password',
        'DATABASE_OPTIONS': {
            'driver': 'sql_server_driver',
            'dsn': 'MSSQL_Logs',
        },
    }
}

If I comment out the first default database definition, and change the name of the mssql database to default, I am able to access the dbshell via:

manage.py dbshell

However, if I try to directly access the mssql database as it is defined above via:

manage.py dbshell mssql

I get an error:

TypeError: handle() takes exactly 1 argument (7 given)

It is almost as though it is unable to parse the definition properly. So my question is basically this: Am I defining the databases incorrectly when pairing them together?

根据此链接https://docs.djangoproject.com/en/dev/ref/django-admin/#django-admin-dbshel​​l ,您应该使用python dbshell --database mssql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM