aras February 2016

using mysql and mongodb in django1.8

I am creating a django web application in which I need to use both mysql and mongodb.

I have used mongoengine for this thus:

mongoengine.connect("mongodb://username:password@localhost:27017/dbname")

In my django/settings.py:

DATABASES = {
   'default': 
       'ENGINE': "django.db.backends.mysql",
        'NAME': "dbname",
        "USER": "username",
        "PASSWORD": "password",
        "HOST": "localhost",
        "PORT": "3306",
}

How can I configure one more connection for MongoDB here and use it to return in routers.py

I'm using Django 1.8, so I cannot use django-norel/django-mongodb-engine.

Answers


the flash February 2016

DATABASES = {
    'default': {
        "ENGINE": "django.db.backends.mysql",
        "NAME": "dbname",
        "USER": "username",
        "PASSWORD": "password",
        "HOST": "localhost",
        "PORT": "3306",
    },
    'users': {
        'NAME': 'user_data',
        'ENGINE': 'django.db.backends.mysql',
        'USER': 'mysql_user',
        'PASSWORD': 'priv4te'
    }
}

The migrate management command operates on only one database at a time. By default, it operates on the default database, but by providing a --database argument, you can tell migrate to synchronize a different database. So, to synchronize all models onto all databases, you would need to call:

$ ./manage.py migrate
$ ./manage.py migrate --database=users

I hope it helps.

Post Status

Asked in February 2016
Viewed 2,642 times
Voted 10
Answered 1 times

Search




Leave an answer