I know you could do it by dumping the database directly, but this could come in handy when you’re trying to migrate from one database to another. AFAIK, copying data from one kind of DB to another kind(think Pgsql to MySql) is a nightmare…

Luckily, Django provides a utility to make this super easy.

python manage.py dumpdata --natural-foreign --exclude contenttypes --exclude auth.permission --exclude admin.logentry --exclude sessions.session --indent 4 > data.json

This will dump all necessary data into data.json.

And to restore, run the following.

/manage.py loaddata data.json

Leave a Reply

Your email address will not be published. Required fields are marked *