connect mongodb with djongo (Django)

旧巷老猫 提交于 2020-06-13 12:28:33

问题


i try connect to mongodb with djongo after reading githup page of djongo and this find same question here but no answer as well change setting.py like this

DATABASES = {
    'default': {
        'ENGINE': 'djongo',
        'NAME': 'namename',
    }
} 

after run python manage.py makemigrate i get this error:

djongo' isn't an available database backend try using "django.db.backend.XXX" where XXX is one of : "mysql" , "oracle" , "postgresql" , "sqlite3"

mongodb version = 3.4

python version = 3.6.3

djogo == 1.2.38


回答1:


You should downgrade Django version to 2.2.8 and reinstall the project.




回答2:


You can use mongoengine to connect django with mongodb and add above line in your settings.py file.

import mongoengine
import pymongo

HOST = 'localhost:27017'

mongoengine.connect(
    db='dbname',
    host=HOST,
    read_preference=pymongo.ReadPreference.PRIMARY_PREFERRED
)


来源:https://stackoverflow.com/questions/59451423/connect-mongodb-with-djongo-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!