Hi Vinay, On 02/02/2016 09:52 AM, 'Vinay Sajip' via Django users wrote: > > On Tuesday, February 2, 2016 at 3:27:10 PM UTC, Carl Meyer wrote: > > Nothing in your code ever "overrides" settings.DATABASES['default']. > > > Dear Carl, > > Thanks for the quick response. I /had/ thought of that, and tried adding > the statement settings.DATABASES['default'] = settings.DATABASES[alias] > just before the with block, and it had no effect - the result was the > same - so I took it out. How else are you supposed to override the > default database?
You can't (well, you might be able to by poking around in the internals of the django.db.connections object, but I'd strongly advise against that). The proper (and thread-safe) way to achieve the equivalent is to do what the third-party project I linked (django-dynamic-db-router) does: write a db router that references some thread-local state to determine which database to route queries to, and write a context manager or whatever to modify that thread-local state. Or just use django-dynamic-db-router, since it already does what you want :-) Carl -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/56B0E273.8070604%40oddbird.net. For more options, visit https://groups.google.com/d/optout.
signature.asc
Description: OpenPGP digital signature

