0

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.

Moe Far
  • 2,742
  • 2
  • 23
  • 41
aras
  • 1
  • 1

1 Answers1

-1
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.

the_unknown_spirit
  • 2,518
  • 7
  • 34
  • 56
  • The question has specifically asked for setting to connect mongodb and mysql db. One is norel database and other is a rel database. The Settings defined above is not proper in such case. – Priyesh Dec 19 '16 at 09:38
  • The answer is completely unrelated to the question – Sdra May 05 '17 at 10:10