lundi 15 juin 2015

How to read table data from non-default database in Django?

My django project uses 2 databases, 1 existing database and another one which I am creating through my project using Models. I have defined db's in settings.py as below :

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    },
    'music': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'myMusicDb.sqlite3'),
    }
}

I generated model data using inspectdb command and everything works fine if I remove the default db from settings.py and make the 'music' db the default db. My query is how to keep both db in settings.py and to work with both DataBases ? Is there any way to tell django to use specific database from settings.py ?

Aucun commentaire:

Enregistrer un commentaire