Sunday, 14 July 2019

MongoDB Setup With Django

SQLITE is default database for Django but if you want to use some different database then need to follow below steps:
I have charted down the steps using no sql db(mongo db).But you can follow below steps as well for other database also.Just you need to be careful about some specific database related stuffs.
1)Install Django
   >pip install django
2)Install mongodb module for django which is "djongo".
   >pip install djongo
3)You might have already created Django  project.If not created, create Django project.
4)Create Django App.
5)Add created app to installed app list.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Your_Custom_App'
]
6)Mongo DB configuration in Django
Open Settings.py file and comment out the other databases configuration and update
the database configuration for mongo as below:
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'Your Mongo DB name',
}
}
Note:Follow below link for Mongo DB creation
7)Now run migration to see the db effect
>python .\manage.py migrate
8)Let us verify these changes into Mongo db.
To manipulate the Mongodb data, We can use MongoDB Compass GUI which is provided by
MongoDB itself.
MongoDB Compass Download Center

No comments:

Post a Comment