2

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

Hoff
  • 38,776
  • 17
  • 74
  • 99

4 Answers4

1

Just add the following to your setting.py file

DATABASE_ROUTERS = ['myapp.routers.MyApp2Router',]

rename your router file routers.py

Aventador
  • 205
  • 2
  • 11
1

path.to.myrouter is just a placeholder.

lprsd
  • 84,407
  • 47
  • 135
  • 168
1

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',]

Amit Baderia
  • 4,454
  • 3
  • 27
  • 19
1

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.

kaapstorm
  • 1,101
  • 7
  • 8