views:

448

answers:

4

I was considering creating a separate SQLite database for certain apps on a Django project.
However, I did not want to use direct SQLite access if possible. Django-style ORM access to these database would be ideal.
Is this possible?

Thank you.

+2  A: 

Currently no -- each project uses one database, and every app must exist within it. If you want to have an app-specific database, you cannot do so through the Django ORM. See the Django wiki page on Multiple Database Support.

John Millikin
A: 

This isn't possible yet, but there is some talk of it on the wiki, Multiple Database Support in Django. It was also brought up during the keynote on the future of Django at DjangoCon 2008 and made one of the higher priority issues.

MFH
+5  A: 

Yes - the low-level API for this is in place, it's just missing a convenient high-level API at the moment. These quotes are from James Bennett (Django's release manager) on programming reddit:

It's been there -- in an extremely low-level API for those who look at the codebase -- for months now (every QuerySet is backed by a Query, which in turn accepts a DB connection as an argument). There isn't any high-level documented API for it, but I know people who are already doing and have been doing stuff like multiple-DB/sharding scenarios.

...it's not necessarily something that needs a big write-up; the __init__() method of QuerySet accepts a keyword argument query, which should be an instance of django.db.models.sql.Query. The __init__() method of Query, in turn, accepts a keyword argument connection, which should be an instance of (a backend-specific subclass for your DB of) django.db.backends.BaseDatabaseWrapper.

From there, it's pretty easy; you could, for example, override get_query_set() on a manager to always return a QuerySet using the connection you want, or set up things like sharding logic to figure out which DB to use based on incoming query parameters, etc., etc.

insin
+2  A: 

Already supported http://docs.djangoproject.com/en/dev/topics/db/multi-db/

sstevko