Menu
Nikesh's Blog
  • Home
  • Tutorials
  • About
  • Contact
  • Blog
Nikesh's Blog

Database Migration in Django

Posted on February 20, 2013May 10, 2019 by nikjha2

Standard Django installation comes loaded with SQLite database which makes it easy to get started right away with building apps as per your need. However, SQLite db is not recommended for production environment so you should consider moving to scalable database options like PostgreSQL, MySql, etc. The steps to follow when migrating from sqlite to MySql are given below.

The steps to do the database migration are given below:

  • STEP 1:

Dump your data to JSON file using the following command

python manage.py dumpdata > datadump.json

  • STEP 2:

Change settings.py file to use your MySql database. You should have installed MySql for this.

Sample configuration for MySql could be:

DATABASES = {
   'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'name_of_db',
        'USER': 'root',   
        'PASSWORD': 'Test@123', # use the password for your MySqlDB
        'HOST': 'localhost',     
        'PORT': '3306'  
}
  • STEP 3:

Open the terminal and execute the following command to exclude the content type data.

from django.contrib.contenttypes.models import ContentType
ContentType.objects.all().delete()
quit()
  • STEP 4:

python manage.py loaddata datadump.json

( For this thing to work you need to have mysql installed on your machine or the server you are hosting your app on )

And you are all set. Let me know in the comments if it works for you.

  • Django
  • Programming
  • Python
  • Tutorials
  • Web Development
  • Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    Recent Posts

    • Database Migration in Django
    • Praesent dapibus, neque id cursus faucibus
    • Testing the Elements
    • Aenean lacinia bibendum nulla sed

    Recent Comments

    • Pavel Ciorici on Testing the Elements
    • Pavel Ciorici on Testing the Elements
    • Pavel Ciorici on Testing the Elements
    • Pavel Ciorici on Testing the Elements

    Archives

    • February 2013
    • January 2013

    Categories

    • News
    • Recipes

    Meta

    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org
    ©2026 Nikesh's Blog | Powered by WordPress & Superb Themes