How to copy database in use to other database in django?

Viewed 18119

I have developed a simple django application using sqlite3. At first, I wanted to keep it simple using sqlite3 but, things are beginning to scale up (Yes, I actually started using that application with sqlite3! Shame on me...) so I want to migrate all my data to postgresql database.

Does django or another third-party provide such feature, or should I suffer for my own stupidity...

4 Answers

If you get errors when loading the data, first dump it like this:

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

as described here:

http://www.denzow.me/entry/2017/09/06/223517

I was in this same situation and was having trouble loading the data into the new postgresql database due to key constraint errors. What worked for me was to rename my 'default' sqlite database to 'sqlite', add my postgresql database connection as 'default', do the data export like this:

python manage.py dumpdata --database sqlite --natural-foreign --natural-primary > sqlite-dump.json

Then load the data into the new database like this:

python manage.py loaddata sqlite-dump.json

(This is with Django 2.2.)

Related