Django SQLite to PostgreSQL database migration

Hemanth S P
Django lions 🔥
3 min readJan 22, 2021

--

Django SQLite to PostgreSQL database migration

Django SQLite to Postgres database migration
Photo by Julia Craice on Unsplash

Hi All, in this article I'm going to show you how to move data from SQLite to Postgres.

Steps are

  1. Take SQLite whole DB dumpdata fixture backup
  2. Create Postgres DB with user and password
  3. Change settings.py
  4. import fixture using loaddata

1. Take SQLite whole DB dumpdata fixture backup.

first, you need to take the backup of the whole DB using the below command

python manage.py dumpdata > whole.json

in this command, some users prefer to use the natural foreign key and primary key but I won't suggest using the bellow command until you get an error while restoring(loaddata) data to Postgres

python manage.py dumpdata — natural-foreign — natural-primary > whole.json

this commands will generate the whole.json in the root of your projects, this means you generated the dumpdata from SQLite in JSON fixture format.

2. Create Postgres DB with user and password.

in this step, you need to install Postgres on your OS like Ubuntu or Mac (google)…

--

--