Mongoengine:ConnectionError:您尚未定义默认连接 [英] Mongoengine: ConnectionError: You have not defined a default connection

查看:1460
本文介绍了Mongoengine:ConnectionError:您尚未定义默认连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的新Django项目中,我设置了一个MongoDb数据库并使用mongoengine模块
,但是我无法在视图中的shell no中正确访问dabase。
ConnectionError:您尚未定义默认连接

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"

我的settings.py包括以下内容:

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',
        )

$ b $模型中的b


import mongoengine

in models.py import mongoengine

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

提前感谢您的帮助

推荐答案

要将django与MongoDB配合使用,请不要使用 https://www.djangoproject.com 并安装其他软件包,如mongoengine,如果遵循这个过程,你会发现很多困难。

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

相反,你需要使用已经被django的no @ rel版本从djangoproject分叉并添加了MongoDB支持,我相信它将使设置过程和开发过程变得更加容易。

Rather you need to use the no@rel 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.

按照此链接安装并使用MongoDB设置django。
http://django-mongodb-engine.readthedocs .org / en / latest / topics / setup.html

Follow this link to install and set up the django with MongoDB. http://django-mongodb-engine.readthedocs.org/en/latest/topics/setup.html

* Django-nonrel和MongoDB上的错误:AutoField(默认主键)值必须是表示MongoDB上的ObjectId的字符串(取而代之的是u'1)请确保您的SITE_ID包含一个有效的ObjectId字符串。*

"*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.*"

https://gist.github.com/ielshareef/2986459

如果您需要更多帮助,请通知我。

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

这篇关于Mongoengine:ConnectionError:您尚未定义默认连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆