Skip to content

Instantly share code, notes, and snippets.

@Lapicher
Forked from sirodoht/migrate-django.md
Created July 17, 2018 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lapicher/ab280b3dfd12d2e70779795918914b29 to your computer and use it in GitHub Desktop.
Save Lapicher/ab280b3dfd12d2e70779795918914b29 to your computer and use it in GitHub Desktop.
How to migrate Django from SQLite to PostgreSQL

How to migrate Django from SQLite to PostgreSQL

Dump existing data:

python3 manage.py dumpdata > datadump.json

Change settings.py to Postgres backend.

Make sure you can connect on PostgreSQL. Then:

python3 manage.py migrate --run-syncdb

Run this on Django shell to exclude contentype data

python3 manage.py shell
>>> from django.contrib.contenttypes.models import ContentType
>>> ContentType.objects.all().delete()
>>> quit()

Finally:

python3 manage.py loaddata datadump.json

Source: https://stackoverflow.com/questions/3034910/whats-the-best-way-to-migrate-a-django-db-from-sqlite-to-mysql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment