Django multiple and dynamic databases

Viewed 19360

I've been evaluating django and wondered if the following is possible. I've already looked at the regular multiple database docs so please don't point me to that because this use case isn't mentioned as far as i can make out. If i'm wrong i take it back :)

I want one main database in which most of my app's models will reside, however one of the app's will need to dynamically create databases, these will be customer specific databases.

The database path (i plan to use sqlite) will be stored in primary database and so the cursor would need to be changed but the model will remain the same.

I would welcome any thoughts on ways to achieve this?

3 Answers

This question is pretty outdated and should be updated.

Django support multiple databases out of the box

Here is many good tutorials [ 1, 2 ] and answers how to manage connections dynamically

Also you may simply use django-dynamic-db-router

Database connection settings may be configured on the fly by using configure method of settings object:

from django.conf import settings

dbs = settings.DATABASES.copy()
dbs['some_new_db'] = {'ENGINE': 'dummy'}

settings.configure(DATABASES=dbs)
Related