简体   繁体   中英

Unable to connect to a MongoDB using Django in Pycharm

I am attempting to create a basic application to get a better understanding of Django. I would really like to use a MongoDB database, and have MongoDB set up locally on my machine. I am able to connect via MongoDB Compass and have created some basic collections/dbs.

In my Django application, I have djongo and pymongo installed. My pip list .

Package     Version
----------- -------
asgiref     3.2.3  
dataclasses 0.6    
Django      3.0    
djongo      1.2.38 
pip         19.3.1 
pymongo     3.10.0 
pytz        2019.3 
setuptools  42.0.2 
sqlparse    0.2.4  
wheel       0.33.6 

In the settings.py I have my DATABASES set up as follows:

DATABASES = {
    'default': {
        'ENGINE': 'djongo',
        'NAME': 'djongo',
        'HOST': 'localhost:27017/djongo',
    }
}

When I attempt to run a migration, I get the following error.

django.core.exceptions.ImproperlyConfigured: 'djongo' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
    'mysql', 'oracle', 'postgresql', 'sqlite3'

I have seen similar posts online, but the solutions (ensuring djongo is installed) have not been working.

How can I use a MongoDB database with a Django application?

Django 3.0 was just released not too long ago which is why djongo wouldn't work yet . Was able to test this, and had no success. After downgrading to Django 2.2 that worked for OP.

You will have to use mongoengine or pymongo to connect to mongodb database instead of djongo.

For mongoengine see this answer:- Setting up Django and mongodb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM