somya singh
somya singh

Reputation: 73

Multiple databases (mongodb[mongoengine] and sql ) with django 1.8

I am using mongoengine with Django and my project needs to connect to one instances of MongoDB while another with sql .How my databse section of setting.py should be like ?

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'admin_db',
        'USER': 'root',
        'PASSWORD': 'root',
        'HOST': 'localhost',
    },

}

from mongoengine import connect
connect(
db='pom',
username='admin',
password='root',
host='mongodb://admin:root@localhost'
)

Upvotes: 2

Views: 2358

Answers (2)

nesdis
nesdis

Reputation: 1220

MongoEngine does not support all Django contrib modules directly. If your projects dont need them (unlikely) you can use mongoengine directly. Otherwise you can also try

Which seems to work fine with the latest Django version.

Upvotes: 1

zaidfazil
zaidfazil

Reputation: 9235

You could add multiple databases for your app in your settings.py like,

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'admin_db',
        'USER': 'root',
        'PASSWORD': 'root',
        'HOST': 'localhost',
    },

    'your_desired_db_name' : {
        'ENGINE' : 'django_mongodb_engine',
        'NAME' : 'db_name'
}

For integration with mongodb, you may need to look up,

Also, you may need to look up Django documentation for multiple databases

Upvotes: 1

Related Questions