[Django]-How to copy database in use to other database in django?

3👍

I am trying to do the same exact thing right now, but I am running into a problem with resolving dependencies basically the same as ticket 16317. But enough about me…

Troubleshooting this led me to find a link for django-smuggler which allows you to create dumps and load data from the admin interface.

It looks promising for any data transfer needed or to use as a backup utility.

👤j_syk

39👍

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)

2👍

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

👤aris

0👍

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

👤dhobbs

Leave a comment