Reputation: 13748
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...
Upvotes: 22
Views: 21312
Reputation: 3477
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.)
Upvotes: 0
Reputation: 24305
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
Upvotes: 2
Reputation: 16435
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
)
Upvotes: 39
Reputation: 6621
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.
Upvotes: 3