Different database types use in a single Django project

31 views
Skip to first unread message

Bbake Waikhom

unread,
May 10, 2019, 7:58:19 AM5/10/19
to Django users
Is there any way that I can use different database type in a single Django project like some model A will use SQL and some model B will use MongoDB? Because in my project some data are better to store in a relational database and some are better to store in a NoSQL database. I've been searching for a while to achieve this but I couldn't find any solution. Please let me know if there is a way. Thank you. 

Chetan Ganji

unread,
May 10, 2019, 8:10:36 AM5/10/19
to django...@googlegroups.com
Hi Bbake,

Django Class Based Views and Models are wired for relational databases only. If you want to use MongoDB with django you have to say bye bye to CBV and Django ORM. There are some third party libraries to map django models to mongo, but IDK how good they are for production use.

One way to solve this problem is use Function Based Views for views where MongoDB will be used. 
You will have to access mongo db using a database driver like pymongo.

If you just need to store the json data, another way to solve this problem is to use django and postgres database. 
PostgreSQL has JSON field, django also supports that. Check the official documents for more info.

If you find any more solutions, please let me know, as I also want to explore the options of using mongo with django.
Thanks in advance. 


Regards,
Chetan Ganji
+91-900-483-4183


On Fri, May 10, 2019 at 5:27 PM Bbake Waikhom <bbak...@gmail.com> wrote:
Is there any way that I can use different database type in a single Django project like some model A will use SQL and some model B will use MongoDB? Because in my project some data are better to store in a relational database and some are better to store in a NoSQL database. I've been searching for a while to achieve this but I couldn't find any solution. Please let me know if there is a way. Thank you. 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b3776d83-18c9-47a0-9a8a-e3e7cb2e849a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Szabolcs Hodossy

unread,
May 10, 2019, 9:13:44 AM5/10/19
to django...@googlegroups.com
Hi Bbake,

You can also use a multi DB setup (I suggest routers), and follow this guide to integrate a Mongo backend:

One drawback that you lose relationships across DBs, but I think you already prepared for that.

Hope this helps,
Szabolcs 

Reply all
Reply to author
Forward
0 new messages