1👍
✅
Ok i found the answer,
what you should do is Connect Django and MongoDB Using Djongo
you can read from here
I RECOMMEND TO FOLLOW MY SETPS.
- go to monogodb site -> clickHere and create free account.
- create new cluster
- then you will reverse to this page if no in the left side press DataBase under DEPLOYMENT and then you get.
- press on Connect buttom
- choose "Connect your application" and then choose python and the last version
after all this you will have this link:
for example!!!
mongodb+srv://<username>:<password>@<atlas cluster>/<myFirstDatabase>?retryWrites=true&w=majority
copy this link and do the next setps:
- go back to your terminal and install this package:
pip install djongo
- and open settings.py
- change your DATEBASE to like this:
DATABASES = { 'default': { 'ENGINE': 'djongo', 'NAME': 'your-db-name', 'CLIENT': { 'host': 'mongodb+srv://<username>:<password>@<atlascluster>/<myFirstDatabase>?retryWrites=true&w=majority' } } }
- in ‘host’ paste the link you copy from monogodb site.
- in ‘NAME’ write your name of the database.
Now that we have the Django project (and app), you can create the collections in MongoDB using the commands:
python manage.py makemigrations <app-name>
python manage.py migrate
if you get error like ‘django.db.utils.databaseerror’
what you should to do is:
It deletes all the files that are in the migrations folder that are in the apps you have created and after that run again the command above.
Source:stackexchange.com