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

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

path.to.myrouter is just a placeholder.

Comments

1

Just add the following to your setting.py file

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

rename your router file routers.py

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.