Simple problem – I’m using multi-db successfully with automatic routing setup as documented on a legacy db (which are unmanaged). Now I want to test it. I’ve already set a testrunner to get around the managed problem and I can confirm that I am creating the databases and as expected.
My problem is that the database routing is still trying to look at the non-test database. How can I setup my routers.py file to look at the test_ database when in test mode and the non-test database any other time.
Should be simple but I’m beating my head on the wall over this one..
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
Much appreciate the additional eyeballs on this 😉
Thanks
OK – so here’s what happened. Turns out it was completely working all along, but two separate issues caused my tests from passing. In this case I am testing the django query methods against the legacy methods. I wasn’t passing my test because the legacy methods where not looking at the test database but rather the original database. I fixed that problem and then I realized that the procedures where not getting created in the testrunner.
Once these two problems were corrected everything magically fell together…
HTH someone.