• Latest
  • Trending
How to migrate development database into production in Django

How to migrate development database into production in Django

May 20, 2022
Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025
ATC Ghana supports Girls-In-ICT Program

ATC Ghana supports Girls-In-ICT Program

April 25, 2023
Vice President Dr. Bawumia inaugurates  ICT Hub

Vice President Dr. Bawumia inaugurates ICT Hub

April 2, 2023
Co-Creation Hub’s edtech accelerator puts $15M towards African startups

Co-Creation Hub’s edtech accelerator puts $15M towards African startups

February 20, 2023
Data Leak Hits Thousands of NHS Workers

Data Leak Hits Thousands of NHS Workers

February 20, 2023
EU Cybersecurity Agency Warns Against Chinese APTs

EU Cybersecurity Agency Warns Against Chinese APTs

February 20, 2023
How Your Storage System Will Still Be Viable in 5 Years’ Time?

How Your Storage System Will Still Be Viable in 5 Years’ Time?

February 20, 2023
The Broken Promises From Cybersecurity Vendors

Cloud Infrastructure Used By WIP26 For Espionage Attacks on Telcos

February 20, 2023
Instagram and Facebook to get paid-for verification

Instagram and Facebook to get paid-for verification

February 20, 2023
YouTube CEO Susan Wojcicki steps down after nine years

YouTube CEO Susan Wojcicki steps down after nine years

February 20, 2023
Inaugural AfCFTA Conference on Women and Youth in Trade

Inaugural AfCFTA Conference on Women and Youth in Trade

September 6, 2022
  • Consumer Watch
  • Kids Page
  • Directory
  • Events
  • Reviews
Thursday, 16 July, 2026
  • Login
itechnewsonline.com
  • Home
  • Tech
  • Africa Tech
  • InfoSEC
  • Data Science
  • Data Storage
  • Business
  • Opinion
Subscription
Advertise
No Result
View All Result
itechnewsonline.com
No Result
View All Result

How to migrate development database into production in Django

by ITECHNEWS
May 20, 2022
in Data Science, Leading Stories
0 0
0
How to migrate development database into production in Django

I search a lot about how to migrate the Django model as well as whole data from the development database to production, and I found lots of explanation about it (One of the good explanations is here) but did not find the easy solution. For this problem, I come up with my solution and I am explaining in this blog how to do that. Before moving to the core thing about this blog, I just want to raise one question and my thought about it.

Do I need to push my migration file to GitHub?

All individuals have their own perspectives. I was also confused about what is the best practice in beginning of my Django journey. After reading this answer from, I tried to push my migrations as well. But I think it is not a good way, so I removed the migrations from GitHub.

YOU MAY ALSO LIKE

French Telco Orange Hit by Cyber-Attack

ATC Ghana supports Girls-In-ICT Program

Okay, now lets start the core thing step by step:

1. Create the backup for your database

The first step is to create the database backup. In my case, I am using the PostgreSQL database. To create the backup file, I simply need to run the following command in the terminal,

pg_dump -U postgres -h localhost -d database > db_backup_2022_05_20.sql

where, postgres is the database user, localhost is the database host, database is the database name and db_backup_2022_05_20.sql is the backup file name.

2. Migrate the Django models to the server

Since this blog is only about how to migrate the database (not about the whole procedure of how to publish the Django site into production), I am only focusing on the database migration. After pulling the code to the server, the first step is to migrate the database tables and schema only by using the Django command,

# make migrations
python manage.py makemigrations

# migrate models
python manage.py migrate

3. Migrate the data

If you want the clean database to initialize the production environment, it is a good way to go, no further action is needed. But if you want to move all the data from the developer environment to production, you need to restore the development database. To do so, if you go with the normal method, you might get an error due to a foreign key, and also duplicated data issue. But to prevent this action and restore data only, the psql provides a nice command line. You just need to do the following,

pg_restore -U postgres -h IP -d database --disable-triggers --data-only db_backup_2022_05_12.sql     

Where, postgres is the database user, ip is the server IP address, database is the database name and db_backup_2022_05_12.sql is the backup file location. If you want to know more about the pg_restore command, please check this official documentation.

This step might throw some error messages or warnings as well, but you can simply ignore those.

4. What next?

If you want to update the Django model, you can first test your model in the development environment. To update those changes on production, you just need to migrate the model as below on the server,

# make migrations
python manage.py makemigrations

# migrate models
python manage.py migrate

The migration file from the development and production environment will be different. If you check both databases from development and production, you will find the different data in the django_migration table.

Congratulations! you finally migrated the database with all the data from the development environment to production.

Source: Tek Bahadur Kshetri
Via: dev.to
Tags: How to migrate development database into production in Django
ShareTweet

Get real time update about this post categories directly on your device, subscribe now.

Unsubscribe

Search

No Result
View All Result

Recent News

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025
ATC Ghana supports Girls-In-ICT Program

ATC Ghana supports Girls-In-ICT Program

April 25, 2023

About What We Do

itechnewsonline.com

We bring you the best Premium Tech News.

Recent News With Image

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025

Recent News

  • Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa July 29, 2025
  • French Telco Orange Hit by Cyber-Attack July 29, 2025
  • ATC Ghana supports Girls-In-ICT Program April 25, 2023
  • Vice President Dr. Bawumia inaugurates ICT Hub April 2, 2023
  • Home
  • InfoSec
  • Opinion
  • Africa Tech
  • Data Storage

© Copyright 2026, All Rights Reserved | iTechNewsOnline.Com - Powered by BackUPDataSystems

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In

Add New Playlist

No Result
View All Result
  • Home
  • Tech
  • Africa Tech
  • InfoSEC
  • Data Science
  • Data Storage
  • Business
  • Opinion

© Copyright 2026, All Rights Reserved | iTechNewsOnline.Com - Powered by BackUPDataSystems

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
Go to mobile version