Django and multiple databases - python

My current Django setup uses MySQL as the main database to store models. Now for my project I need to connect to a remote PostgreSQL database and retrieve data from it. Is it possible to do this by using built-in Django and Python features or I will need to use library such as Psycopg2?
It would be great for me, if I will be able to use the Object-relational mapper of Django for this remote database.
Any ideas would be more than welcome.

Django Project is working on Multiple Database Support. There is also a recent (Nov 10 2009) blog post about "The state of MultiDB (in Django)".
Update: Multiple Databases is supported since Django v1.2 (release May 2010).

Related

Django with NoSQL database

I am working with an Django application which uses Django 1.8 version.
Most of the data we deal with is JSON formatted ones. We are trying to implement any NoSQL database.
But I see that MONGODB is not compatible for version 1.8 and over and Is there any NoSQL database that can be efficiently mapped to Django 1.8 or over ??
Thanks in advance.
NoSQL databases are not officially supported by Django itself. There are, however, a number of side project and forks which allow NoSQL functionality in Django, like Django non-rel.
You can also take a look on the wiki page which discusses some alternatives.
This is quoted from the django official documentation
Here is an interesting repo for allowing using MongoDB as your django backend. It works by compiling SQL commands into MongoDB document queries.
Most of the basic stuff like django admin, django session etc all work.
https://github.com/nesdis/djongo
Years after (2022), djongo is still the only option which works fine with Django 3.0.x as well (with some constraint restrictions) in NoSQL environment.
But now that Django's 4.0.1 major release is in the air, djongo's latest 1.3.6 (released in June 2021 according to pypi) is beginning to break. In my experience with Django==4.0.4 and djongo==1.3.6 together, almost none of the select/update queries work, and SQLDecodeError exceptions lay around in console.
djongo maintainer(s) have created paid subscription plans as well, but I have not been their customer like that so can't comment anything about the commercialized version of djongo. Rest, the open-sourced AGPL licensed djongo is the only best option for unpaying developers to use Django with MongoDB, given that the developer restricts themselves to Django 3.0.x.
I've been using Django==3.0.5 with djongo==1.3.6, to be specific here, which works fine in most of the circumstances.

Is Django itself a backend?

I have been reading into Python/Django but I was unable to find good info. I have learned that Django is a backend, but some people are saying that django itself runs on PostGreSQL?
So I need to learn both python/PostGreSQL? Or is DJANGO itself a backend?
Django is a python web framework. It can be used to create a backend. Django does not run on PostgreSQL, it can work with it as a database. But Django can work with many other databases as well, e.g. mysql, sqlite etc. If you want to learn web programming in python, then Django is a reasonble choice. However, there are many other popular alternatives to the Django web framework.

What versions of Django does the Django MongoDB Engine support?

Is the maintenance and support for Django MongoDB Engine still active? I searched online and found that the original author of Django MongoDB Engine already quit the project. I am wondering if it supports Django 1.8. If not, I would switch to another mongo ORM such as mongoengine.
Related question (with no answers): configuration of django_mongodb_engine with django 1.8 or any other way to use MongoDB
Django-mongodb-engine is no longer keeping up with the latest Django improvements As a web developer you can take up the challenge of connecting Django to MongoDB in several ways, but depending on what strategy you chose you may run out support from the authors sooner or later. There are several reasons for that. Listed below are some:
Use a MongoDB compatible model framework: Use a third party framework like MongoEngine or Ming in your django projects. However will miss out on:
1500+ core contributors to the project,
Hourly fixes and ticket resolution,
Ramp down on the expertise of existing Django models and ramp up on the new model framework.
Perhaps the biggest drawback is that your project can’t use any of Django’s contrib models! Forget about using Admin, Sessions, Users, Auth, etc., contrib modules for your project!
Alternatively you can try:
Django SQL to MongoDB connector — Djongo: The strategy is to translate Django SQL query syntax generated by the Django ORM into pymongo commands. Djongo is a SQL to MongoDB query compiler. It translates every SQL query string into a mongoDB query document.
SQL syntax will never change regardless of future additions to Django, by using a connector instead of a different ORM, your project will work on all versions of Django.

How can I switch my Django project's database engine from Sqlite to MySQL?

I need help switching my database engine from sqlite to mysql. manage.py datadump is returning the same error that pops up when I try to do anything else with manage.py : ImproperlyConfigured: Error loading MySQL module, No module named MySQLdb.
This django project is a team project. I pulled new changes from bitbucket and our backend has a new configuration. This new configuration needs mysql (and not sqlite) to work. Our lead dev is sleeping right now. I need help so I can get started working again.
Edit: How will I get the data in the sqlite database file into the new MySQL Database?
According to the Database setup paragraph in Django docs:
By default, the configuration uses SQLite.
If you wish to use another database, install the appropriate database
bindings...
And Get your database running page says:
If you’re using MySQL, you’ll need the MySQL-python package, version
1.2.1p2 or higher.
To use MySQL backend you need a tool that would help Django talk to the database, an adapter.
In other words, MySQL-python (aka MySQLdb) package needs to be installed.
Try the followings steps:
1. Change DATABASES in settings.py to MYSQL engine
2. Run $ ./manage.py syncdb

Difference among Mongoengine, flask-MongoEngine and Django-MongoEngine?

What are the differences between the Mongoengine, flask-MongoEngine and Django-MongoEngine projects?
I am using Mongoengine in my Django project. Will I get any benefits if I use Django-MongoEngine instead?
Django MongoEngine aim is to provide better integration with Django - however currently (June 2014) its not stable and the readme says
DO NOT CLONE UNTIL STABLE
So beware!
In addition to the other answers, flask mongoengine adds support for wtforms. If your not using flask admin, or doing server side rendering, chances are you don't need flask-mongoengine. You can just go with mongoengine
flask-mongoengine adds a few helpers to integrate MongoEngine into a Flask application.
Connection definition in Flask parameters
get_or_404 / first_or_404 shortcuts (abort 404 if document not found)
paginator added to QuerySet object
automatic form generation using WTForms
django support was pulled off Mongoengine into a separate code (django-mongoengine). Although it has no release, it seems to be worked on (see the recent commits).
Django framework provides a unified unified interface to connect to a Database backend which is usually an SQL based database such as SQLite or Postgresql. That means that the developer does not have to worry about writing code specific to the database technology used, but defines Models and perform transactions and run all kinds of queries using the Django database interface. Flask does the same.
Django does not support MongoDB from the get-go. To interact with MongoDB databases, Collections and Documents using Python one would use the PyMongo package, that has a different syntax, and paradigms than Django Models or Flask's.
MongoEngine wraps PyMongo in way that provides a Django-like Database for MongoDB.
MongoEngine-Django tries to allow Django web-apps developers to use a Mongo database as the web-app backend. To provide the Django Admin, Users, Authentication and other database related features that are available in Django usually with an SQL backend.
MongoEngine-Flash tries to allow Flask web-apps developers to use a Mongo database as the web-app backend.
Personally, I prefer using a structured SQL database for the web-app essentials, and PyMongo, or MongoEngine to interface with any further Mongo Databases where unstructured big data might reside...

Categories