开发者

Django models interface with dynamic connection

I have databases with identical schemas spread over several servers and I need to route a Django model to read from the databases on different servers. I know I can use routers to send reads to different databases in settings.DATABASES, but the addresses could change at any time and keeping DA开发者_如何学编程TABASES up-to-date would be impractical.

Django appears to route models based mostly database aliases, which it uses to look up the proper connection in django.db.connections. Is there a good way to dynamically add connections and aliases to the ConnectionHandler instance without having to hack the _connections attribute? Should I find some way to dynamically populate settings.DATABASES?


Should I find some way to dynamically populate settings.DATABASES?

If you mean to alter settings.py at runtime, you should not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜