0

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.

  • Are you sure you have data in your `databaseproject.db`? – Manzurul Hoque Rumi Jan 30 '22 at 10:25
  • @Manzurul Hoque Rumi I have opened "databaseproject.db" using sublime and i have found a format of numbers like this (5351 4c69 7465 2066 6f72 6d61 7420 3300 1000 0101 0040 2020 0000 0027 0000 0022 0000 0000 0000 0000 0000 0038 0000 0004 0000 0000 0000 0000 0000 0001 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0027 002e 303a 0500 0000 010f fb00 0000 0016) , because as i say the person who give me the backup work on windows , How i can be sure that I have data there! – Helena Perroni Jan 30 '22 at 13:09

2 Answers2

1

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
Manzurul Hoque Rumi
  • 2,911
  • 4
  • 20
  • 43
0

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.

P. Naoum
  • 457
  • 5
  • 14