Version 1 (modified by 18 years ago) ( diff ) | ,
---|
Multiple Database Support
Work is underway on a patch for #1142, which will add support for multiple database connections. This page documents my current plan and progress towards a fully working patch.
The plan
- Add a new settings variable, DATABASES. DATABASES is a dict of named database connection parameter sets. In each set, the keys are the same as the standard database connection settings variables.
DATABASES = { 'a': { 'DATABASE_ENGINE': 'sqlite3', 'DATABASE_NAME': '/tmp/dba.db' }, 'b': { 'DATABASE_ENGINE': 'sqlite3', 'DATABASE_NAME': '/tmp/dbb.db' }}
- Add db_connection to Meta. This allows model classes to specify which connection they should use.
class Artist(models.Model): name = models.CharField(maxlength=100) alive = models.BooleanField(default=True) def __str__(self): return self.name class Meta: db_connection = 'a' class Widget(models.Model): code = models.CharField(maxlength=10, unique=True) weight = models.IntegerField() def __str__(self): return self.code class Meta: db_connection = 'b'
Attachments (6)
-
p4.diff
(36.2 KB
) - added by 18 years ago.
Current (incomplete) patch as of 2006-06-08
-
naive-transaction.diff
(3.1 KB
) - added by 18 years ago.
naive first pass at allowing transactions to work
-
p5.diff
(52.8 KB
) - added by 18 years ago.
Updated patch including transaction support
-
naive-related.diff
(2.4 KB
) - added by 18 years ago.
naive first pass at getting related fields to work
-
multidbsample.tar.gz
(5.9 KB
) - added by 18 years ago.
Small sample of connecting to two databases, and pulling data back from both of them.
-
djangomultidbhowto.doc
(52.0 KB
) - added by 18 years ago.
A guide to installing the Multiple DB Branch, and then creating a project to work with multiple legacy databases.
Download all attachments as: .zip
Note:
See TracWiki
for help on using the wiki.