django.core.exceptions.ImproperlyConfigured:' django_mongodb_engine'不是可用的数据库后端

时间:2015-05-29 10:19:31

标签: python django mongodb django-mongodb-engine

我无法正常运行django mongo引擎。

我在settings.py中的数据库条目是

DELIMITER $$

CREATE TRIGGER moveToHistory AFTER UPDATE ON equip
FOR EACH ROW
BEGIN

IF NEW.checkedOutBy <> Old.checkedOutBy
BEGIN

IF OLD.checkedOutBy IS NOT NULL AND NEW.checkedOutBy IS NULL THEN
     INSERT INTO equipmentHistory(assetId, operation, createdBy, creationDate)
     VALUES(new.assetId, 'CheckIn', eid, Date(sysdate()))
     NEW.status = 'CheckedIn';
ELSE IF OLD.checkedOutBy IS NULL AND NEW.checkedOutBy IS NOT NULL THEN
     INSERT INTO equipmentHistory(assetId, operation, createdBy, creationDate)
     VALUES(new.assetId, 'Checkout', eid, Date(sysdate()))
     NEW.status = 'CheckedOut';
END IF
END
END$$

DELIMITER ;

我的pip冻结结果是

DATABASES = {
'default': {
    'ENGINE': 'django_mongodb_engine',
    'NAME': 'local',
}
}
运行时出现

错误

Django==1.8.2
django-mongodb-engine==0.5.2
djangotoolbox==1.6.2
pymongo==3.0.2

python manage.py runserver

有任何建议如何解决这个问题。

5 个答案:

答案 0 :(得分:3)

根据documentation,您还需要安装django-nonrel

答案 1 :(得分:0)

但是,主要的缺点是django-nonrel仅在您使用Python2.x时有效,它无法与Python3.x一起使用

答案 2 :(得分:0)

我有这个问题。如果您计划使用Django 1.7.x, 1.8.x,那么工作正常的库是:
django-mongoengine v0.2.1

在更高版本(pip install django-mongoengine)中,它强制安装Django 2.x(您仍然可以通过添加--no-deps来取消)但是,如果强制使用django-mongoengine包版本,则会减少麻烦通过: `pip install git + https://github.com/MongoEngine/django-mongoengine@v0.2.1

requirements.txt文件仍然是这样的:

Django==1.7.11
-e git+https://github.com/MongoEngine/django-mongoengine@4ea7168faf9b6f67a5c9e8e82690b4310aca0ff0#egg=django_mongoengine-v0.2.1
djangotoolbox==1.8.0
mongoengine==0.13.0
pymongo==2.8
pyserial==3.1.1
requests==2.13.0
six==1.10.0
wheel==0.24.0

django-mongoengine的好处是,mongoengine很容易让你access pymongo方法:

class Post(Document):
    #fields    

collection = Post._get_collection()
collection.update({}, {"$set": {"newfield": 1}}, multi=True)

答案 3 :(得分:0)

与通过ide安装相比,尝试卸载“ Pymongo”并将其安装为“ pip install pymongo”

答案 4 :(得分:-1)

发生此错误是因为django utils.py文件无法识别django是可用的后端,要解决此错误,请按照以下步骤操作:

1. Go to C:\Users\User\AppData\Local\Programs\Python\Python38-32\Lib\site-packages 
   and find the django folder .
2. Now cut and paste the django folder in the 
   C:\Users\User\AppData\Local\Programs\Python\Python38-32\Lib\site -
   packages\django\db\backends directory .
3. Now u might be getting the error cannot import six from django.utils. For 
   resolving that go to C:\Users\User\AppData\Local\Programs\Python\Python38- 
   32\Lib\site-packages\django\db\backends\django\operations.py file and replace the 
   line from django.utils import six , datetime to from django.utils import datetime 
   and beneath that just write import six .
4. Now in the settings.py file of your django project add the lines
  DATABASES = {
   'default': {
    'ENGINE': 'django.db.backends.djongo',
    'NAME': 'admin',
 }
}
5. Thats it