[英]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. 我目前正在使用用C#编写的asp.NET内部网站,并在Django Web框架中重做它。 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.
在确定了.NET站点正在使用的所有当前数据源之后,我开始配置和测试我从Django框架内连接到这些数据库的能力。
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: 如果我注释掉第一个默认数据库定义,并将mssql数据库的名称更改为default,则可以通过以下方式访问dbshell:
manage.py dbshell
However, if I try to directly access the mssql database as it is defined above via: 但是,如果我尝试通过以下方式直接访问上面定义的mssql数据库:
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-dbshell ,您应该使用python dbshell --database mssql
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.