Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 to dabase nore in shell no in views. "ConnectionError: You have not defined a default connection"

My settings.py includes the following:

DATABASES = {
    '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')
AUTHENTICATION_BACKENDS = (
       'mongoengine.django.auth.MongoEngineBackend',
        )

in models.py import mongoengine

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

Thanks you in advance for your help

like image 856
c24b Avatar asked Feb 17 '14 00:02

c24b


1 Answers

In your settings.py file replace:

mongoengine.connect(_MONGODB_NAME, 'localhost:27017')

with the below code (notice the added 'host='):

mongoengine.connect(_MONGODB_NAME, host='localhost:27017')
like image 142
NiKS001 Avatar answered Oct 03 '22 22:10

NiKS001