Mongoengine: ConnectionError: You have not defined a default connection


In my new Django project I set up a MongoDB database and use mongoengine module
but I can’t properly access the dabase neither in shell nor in views.

"ConnectionError: You have not defined a default connection"

My includes the following:

    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'DaTaBaSe',                      
        'USER': 'root',
        'PASSWORD': '',
        'HOST': 'localhost', 
        'PORT': '3306',                  
    'tracking': {
        'ENGINE': 'django.db.backends.dummy',
        'NAME': 'analytics',

import mongoengine
SESSION_ENGINE = 'mongoengine.django.sessions'
mongoengine.connect(_MONGODB_NAME, 'localhost:27017')


import mongoengine

from mongoengine import *
from myproject.settings import _MONGODB_NAME
mongoengine.connect(_MONGODB_NAME, 'localhost:27017')


To use django with MongoDB do not use the django package available on and install other packages like mongoengine, if follow this process you will find lot of difficulties.

Rather you need to use the [email protected] version of django that has been forked from djangoproject and added MongoDB support and I am sure it will make setup process and development process lot easier.

Follow this link to install and set up the django with MongoDB.

One more thing you may find the error below, while setting up django.

“*Error on Django-nonrel and MongoDB: AutoField (default primary key) values must be strings representing an ObjectId on MongoDB (got u’1′ instead). Please make sure your SITE_ID contains a valid ObjectId string.*”

Follow this link to fix.

Please let me know if you need any more help on this.

Answered By – Shanki

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published