Django ; How i can migrate a project done with the sqlite3 to postgresql

142 views Asked by At

From days my friend has worked in the OS:windows and he did a part of the django application using the database :sqlite3 , he give me a backup of his work to complete my part , on the backup i have found a database named databaseproject.db, My question here that am using Linux as an OS and postgresql , How I can migrate this database databaseproject.db(it's an sqlite3 database ) to postgresql.

Ps: when i have tried do the command below on the directory(after copied the project in a virtual environement on my linux):

python manage.py dumpdata --natural-foreign \
   --exclude=auth.permission --exclude=contenttypes \
   --indent=4 > data.json

----> command go without errors, Here i have found the data.json contain an empty list..

So i want to know , How i can correctly migrate from sqlite3 to postgresql.?

Thanks in advance.

2

There are 2 answers

0
P. Naoum On

Easiest way would be using dumpdata followed by loaddata here.

If you see an empty dump file, you need to investigate a bit.

First, you can use something like Sqlite Browser to make sure that data exists inside the shared database, make sure that application models contain data not the django built in models.

Then you would need to make sure that the application is added inside INSTALLED_APPS in setttings.py.

And that the application contains a file named models.py containing the app models.

0
Manzurul Hoque Rumi On

Open your database by any SQLite Viewer and then you can make sure whether you have data or not. If you have data, then dump your them by your following command:

python manage.py dumpdata --natural-foreign \
   --exclude=auth.permission --exclude=contenttypes \
   --indent=4 > data.json

next update your database settings with PostgreSQL configuration and then load your data into your PostgreSQL database by following command:

python manage.py loaddata data.json