I've followed these instructions to set up Django with multiple databases. It's working as intended in my local dev environment (win7), however, when I upload the project to my live server (webfaction), I get
ImproperlyConfigured: Error importing database router MyCustomRouter: "No module named path.to.my.router"
From the Django shell, I can import MyCustomRouter开发者_如何学编程:
>>> from path.to.my.router import MyCustomRouter
>>>
I'm running django 1.2.1 and python2.6 both locally and on live server...
Any hints what could be causing this behavior or how to debug are be greatly appreciated!
Cheers,
Martin
I had the same problem. I had defined a router in models.py. Moving the class definition into its own file (I named mine router.py), and updating settings.py accordingly, resolved the error.
path.to.myrouter
is just a placeholder.
Just add the following to your setting.py file
DATABASE_ROUTERS = ['myapp.routers.MyApp2Router',]
rename your router file routers.py
Example:
My projects consists of multiple apps like 'payroll', 'taxation', 'helpdesk' etc.
I am using 2 db here - default and prod_db
This is how i set router path,
1. In payroll app i created "dbrouter.py" file
2. In dbrouter.py, i define DbRouter class (refer this for router code - https://docs.djangoproject.com/en/2.1/topics/db/multi-db/)
3. In settings.py, path is set
DATABASE_ROUTERS = ['payroll.dbrouter.DbRouter',]
精彩评论