Skip to content

Switch to another Deploying Env. without Losing Data .For e.g., switching from SQLite database to MySQL Database but you can use this way on any type of database.

Notifications You must be signed in to change notification settings

reactVishnu/transfer_data_to_another_db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 

Repository files navigation

Seamless Data Migration: Effortless Transfer Between Databases

Overview

The Django Data Migration Tutorial is a step-by-step guide to seamlessly transfer data between databases and deploy your Django application to different environments without losing critical data. This tutorial focuses on flexibility, allowing users to switch between different database backends such as SQLite, MySQL, or any other supported by Django.

Key Features

  • Database Switching: Easily switch between different database backends without data loss.
  • Step-by-Step Guide: Follow a comprehensive guide to migrate data smoothly.
  • Compatibility: Applicable to various databases supported by Django.
  • Deployment Readiness: Ensure your application is ready for deployment in different environments.

Transferring Data to another Db in a Django Application

Helps In Switch to another Deploying Env. without Losing Data

image.png

Step 1: Generating a JSON file which includes your db content

This command dumps the contents of your database in JSON format and saves it to a file named "data.json"

python manage.py dumpdata > data.json

image.png

Note: For excluding any models use "--exclude"

python manage.py dumpdata --exclude auth.permission --exclude contenttypes > data.json

Step 2: Add your new database to the settings.

Add the new database to your settings.py file like this and run all your migrations for creating the table structure and DB schema.

image.png

python manage.py migrate --database=new

After migrations

image.png

Step 3: Convert the data.json to UTF-8 and Load your data into new db

Your data.json is of UTF-16LE and you need to convert it into UTF-8 and than load your data to new database.

image.png

 python manage.py loaddata data.json --database=new

image.png

Step 4: All data is succesfully transferred to new DB

This process is useful for creating backups, migrating data between databases, or sharing sample data with others working on the project. Keep in mind that the **dumpdata** and **loaddata** commands are part of Django's serialization framework, and they work with various serialization formats, not just JSON.

image.png

About

Switch to another Deploying Env. without Losing Data .For e.g., switching from SQLite database to MySQL Database but you can use this way on any type of database.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published