Skip to content

Instantly share code, notes, and snippets.

@sirodoht
Last active April 20, 2024 09:52
Show Gist options
  • Save sirodoht/f598d14e9644e2d3909629a41e3522ad to your computer and use it in GitHub Desktop.
Save sirodoht/f598d14e9644e2d3909629a41e3522ad 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

@Omkar-Jawalkar
Copy link

It is not working for me, when I run python3 manage.py migrate --run-syncdb, after change settings.py to Postgresql, I get the following Error: django.db.utils.ProgrammingError: relation "etl_categories" does not exist Am I making a mistake? SOLVED: Yes I was making a mistake. Since some views and forms in my app use some Models, when I run "python manage.py migrate" the ERROR above appear. If you are having the same problem just delete or comment all your views, forms and urls that uses any model. Then Follow the steps (migrate, load again your data) and finally uncomment/restore your files.

@gamonsalve, thanks!!

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