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?
Based on this link https://docs.djangoproject.com/en/dev/ref/django-admin/#django-admin-dbshell, you should use python dbshell --database mssql
.
精彩评论