I need to migrate a complex project from sqlite to PostgreSQL. A lot of people seems to have problem with foreign keys, data truncature and so on...
The following is a refinement of Nimo's answer and Stephen's answer for Django 1.7+:
./manage.py dumpdata --natural-primary --natural-foreign > dump.json
DATABASES
in settings.py
to point to the new (PostgreSQL) db../manage.py migrate
./manage.py loaddata dump.json
One problem I encountered is that SQLite doesn't seem to actually enforce the maximum length for CharField
s. In my case, this made the loaddata
step fail. I was able to find (and delete) model instances with too long CharField
values via:
MyModel.objects.extra(where=["LENGTH(text) > 20"]).delete()
Once I did this before step 1. above, everything worked.