Skip to content Skip to sidebar Skip to footer

Django - Multiple Db + Multiple Models

I have two databases and two models:one the admin and the is user. I want to sync my models to the two databases; admin model to database A and user model to database B; so my prob

Solution 1:

In your settings, the DATABASE_ROUTERS list should contain python path (ie : 'modules.data.admin_db_router.AdminRouter', ...), not filesystem path. Note that usual PYTHONPATH / sys.path requirements apply, ie in the above example the modules and data directories must be python packages and the directory containingmodules must be in your sys.path one way or another.

As a side note, Python is not Java so you don't need a different module per class. I'd personally put both AdminRouter and UserRooter classes in a same routers.py module.

Post a Comment for "Django - Multiple Db + Multiple Models"