単純な問題 -レガシーデータベース (管理されていない) に記載されているように、自動ルーティング設定でマルチデータベースを正常に使用しています。今、私はそれをテストしたいと思います。管理された問題を回避するために既にテストランナーを設定しており、データベースを作成していることを確認でき、期待どおりです。
私の問題は、データベース ルーティングがまだ非テスト データベースを見ようとしていることです。テスト モードのときに test_ データベースを参照し、それ以外のときは非テスト データベースを参照するように routers.py ファイルを設定するにはどうすればよいですか。
シンプルなはずですが、この壁に頭を悩ませています..
FWIW:
class PmCatalogRouter(object):
"""A router to control all database operations on models in
the PmCatalog application"""
def db_for_read(self, model, **hints):
"Point all operations on pmCatalog models to 'catalog'"
if model._meta.app_label == 'pmCatalog':
return 'catalog'
return None
def db_for_write(self, model, **hints):
"Point all operations on pmCatalog models to 'catalog'"
if model._meta.app_label == 'pmCatalog':
return 'catalog'
return None
def allow_syncdb(self, db, model):
"Make sure the pmCatalog app only appears on the 'catalog' db"
if db == 'catalog':
return model._meta.app_label == 'pmCatalog'
elif model._meta.app_label == 'pmCatalog':
return False
return None
これに関する追加の目玉に感謝します;)
ありがとう