On Wed, Mar 21, 2012 at 2:55 AM, Chris Ghormley <[email protected]> wrote: > I'm having trouble with database routers in a Django 1.3.1 project. > I'm by no means a Django or Python expert, but I've been using Django > for a few years now. When I enable any kind of router in my project, > it throws a TypeError like the following: > > "unbound method db_for_read() must be called with DBRouter instance as > first argument (got ModelBase instance instead)" > > I've tried a few different examples based on the Django documentation, > but it seems like I am missing something basic here. > > Does anybody have an idea what I've done wrong? Please let me know if > you need more information. > > Here's some background: > > The new database is used by a new app with a model in the app's > models.py. Using the shell I've proved that the database and model are > OK. > > The routers.py is in the new app. The settings file imports the router > class, and includes the following line: > > DATABASE_ROUTERS = [ DBRouter, ] >
https://docs.djangoproject.com/en/1.3/topics/db/multi-db/#topics-db-multi-db-routing """ Then, in your settings file, add the following (substituting path.to. with the actual python path to the module where you define the routers): DATABASE_ROUTERS = ['path.to.MyAppRouter', 'path.to.MasterSlaveRouter'] """ DATABASE_ROUTERS is supposed to be a list of strings, each string denoting the python path and class name of a DB router class. You are setting it to a list of klasses. Django will take care of instantiating instances of the DB router classes as needed. Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

