views:

495

answers:

2

Hi There,

I need to connect to multiple databases in my django application. I want to make connections to all the databases when ever i start the application and use those connections for all the requests. But I did not understand how to do that (setting these databases connections in global environment).

I tried to set database connections in settings.py and i tried to access those connections in my views using from django.conf import settings, But it is creating new database connections when ever new request comes.

Because of this my website always gives too many database connections error.

Can you please help me how to set these mysql connections in global environment?

A: 

The Django ORM does not support multiple databases.

There are some patches to modify Django with multiple database support called django-multidb You may have some luck with these, although they are a rather old.

Multiple DB support for Django is a planned feature.

arcanum
+1  A: 

Not only is this a planned feature, but one of this years GSOC projects is for multi database support. Alex Gaynor is working on it with Russell Keith-Magee as mentor. So I'm sure the result will be good.

The description of the project:

Django current has the low level hooks necessary for multiple database support, but it doesn't have the high level API for using, nor any support infrastructure, documentation, or tests. The purpose of this project would be to implement the high level API necessary for the use of multiple databases in Django, along with requisit documentation and tests.

googletorp