I want to use both mysql and mongodb for my auction site.
Product store in MongoDB, Order store in Mysql
http://www.slideshare.net/spf13/hybrid-mongodb-and-rdbms-applications
How can I do this in Django
It's common to use MySQL as the primary storage and MongoDB as caching/intermediate storage for speed. You can for example have read-intensive data in MongoDB. The data for generating reports is perfect for a relational system like MySQL.
There are three ways to connect Django to MongoDB: PyMongo: PyMongo is the standard driver through which MongoDB can interact with Django. It is the official and preferred way of using MongoDB with Python. PyMongo provides functionality to perform all the database actions like search, delete, update, and insert.
Django officially supports the following databases: PostgreSQL. MariaDB. MySQL.
Process to get MySQL data So, we need to create the model of the data and implement that model into the db of django. Open 'models.py' and put in the following code. The database table 'students' will be created by the following code. Suppose we have the following records in the 'students' table.
First use standard rdbms database backend. Next try to add django-nonrel/django_mongodb_engine . Django supports multiple databases.
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'USER': 'mysql_user',
'PASSWORD': 'priv4te'
},
'product_db' : {
'ENGINE' : 'django_mongodb_engine',
'NAME' : 'my_database'
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With