django.core.exceptions.ImproperlyConfigured: '

2020-08-22 06:26发布

问题:

I'm unable to run django mongo engine properly.

My database entry in settings.py is

DATABASES = {
'default': {
    'ENGINE': 'django_mongodb_engine',
    'NAME': 'local',
}
}

and my pip freeze result is

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

error while running

python manage.py runserver

is

django.core.exceptions.ImproperlyConfigured: 'django_mongodb_engine' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
u'base', u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
Error was: cannot import name BaseDatabaseFeatures

Any suggestions how to solve this.

回答1:

You need django-nonrel installed as well, as per the documentation.



回答2:

But, the main drawback is django-nonrel works only if you use Python2.x, it cannot work with Python3.x



回答3:

I had this issue. If you plan to work with Django 1.7.x, 1.8.x, a lib that works just fine is:
django-mongoengine v0.2.1

In later versions (pip install django-mongoengine) it comes forced the install of Django 2.x (which you can still cancel by adding --no-deps) but still, less hassle if force the django-mongoengine package version by: `pip install git+https://github.com/MongoEngine/django-mongoengine@v0.2.1

The requirements.txt file remains something like this:

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

The good of of django-mongoengine is that mongoengine easily allows you to access pymongo methods:

class Post(Document):
    #fields    

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


回答4:

This error occurs because the django utils.py file does not recognize that django is an available backend, to solve this error, please follow these steps:

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


回答5:

Try uninstalling 'Pymongo' and install it as 'pip install pymongo' as compared to installing it via an ide