settings.py 中的 Django 项目多数据库配置
我目前正在使用 C# 编写一个 asp.NET 内部网站,并在 Django Web 框架中重做它。在确定 .NET 站点当前使用的所有数据源后,我开始配置和测试从 Django 框架内连接到这些数据库的能力。
- 平台: Archlinux
- Django 版本: 1.3.1
- Python 版本: 2.7
问题: 每当我尝试连接到任何未定义为默认数据库的数据库时,我都无法这样做。此外,只有当它被定义为不是默认值时,我才能连接到任何数据库。
为了进一步说明这一点,我将提供经过编辑的示例:
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',
},
}
}
如果我注释掉第一个默认数据库定义,并将 mssql 数据库的名称更改为默认值,我可以通过以下方式访问 dbshell:
manage.py dbshell
但是,如果我尝试直接访问上面定义的 mssql 数据库通过:
manage.py dbshell mssql
我收到一个错误:
TypeError: handle() takes exactly 1 argument (7 given)
它几乎就像无法正确解析定义一样。所以我的问题基本上是这样的:将数据库配对在一起时我是否错误地定义了数据库?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基于此链接 https://docs.djangoproject。 com/en/dev/ref/django-admin/#django-admin-dbshell,您应该使用
python dbshell --database mssql
。Based on this link https://docs.djangoproject.com/en/dev/ref/django-admin/#django-admin-dbshell, you should use
python dbshell --database mssql
.