简单的问题 - 我成功地使用了多数据库和自动路由设置,如旧数据库(非托管)中记录的那样。现在我想测试它。我已经设置了一个测试运行程序来解决托管问题,并且我可以确认我正在创建数据库并且符合预期。
我的问题是数据库路由还在尝试查看非测试数据库。如何设置我的 routers.py 文件以在测试模式下查看 test_ 数据库,而在其他任何时候查看非测试数据库。
应该很简单,但我在这个墙上敲我的头..
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
非常感谢对此的额外关注;)
谢谢