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

yasar picture yasar · Aug 9, 2011 · Viewed 15k times · Source

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...

Answer

rewritten picture rewritten · Aug 10, 2011

First, execute

manage.py dumpdata > out.json

then change your DB config, migrate (or syncdb) and finally

echo "delete from auth_permission; delete from django_content_type;" | python manage.py dbshell

(If you have Django older than 1.11, you need to use

echo "delete from django_content_type;" | manage.py dbshell

)

Then load the JSON file:

manage.py loaddata out.json

(as of 2013 django_contenttype is replaced with django_content_type)