デフォルトのデータベースにクエリ セットを使用できます。しかし、別のデータベースにクエリ セットを使用すると、例外がスローされます。
私のアプリケーションでは、2 つのデータベースを使用しています。sqlite と Mysql
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'abc.db', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # 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.
},
'second' : {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'abc', # Or path to database file if using sqlite3.
'USER': 'abcdb', # Not used with sqlite3.
'PASSWORD': 'xxxxx', # 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.
}
}
最初のデータベースにクエリ セットを使用すると、例外がスローされません。2 番目のデータベースを使用している間は、スロー テーブルは使用できません。
TemplateSyntaxError at /abc/xyz/
Caught DatabaseError while rendering: no such table: second.tablename
Request Method: GET
Request URL: http://127.0.0.1:8000/xxx/yyyy/?q=abcd
Django Version: 1.3.1
Exception Type: TemplateSyntaxError
Exception Value:
Caught DatabaseError while rendering: no such table: second.tablename