Created
July 29, 2018 17:49
-
-
Save Eduard-gan/3147d3f3159300443533849ff4fbadbf to your computer and use it in GitHub Desktop.
Move Django project from Sqlite to Postgres
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to migrate Django from SQLite to PostgreSQL | |
Dump existing data with currens Sqlite db configured: | |
``` | |
./manage.py dumpdata > dump.json | |
``` | |
Switch DATABASE configuration in settings.py to Postgres backend. | |
Make sure you can connect on PostgreSQL. Then: | |
``` | |
./manage.py migrate | |
``` | |
Run this on your Postgres instance(my is in Docker container) to exclude contentype data | |
``` | |
docker exec -it your_postgres_container_name bash | |
su postgres | |
psql | |
\c your_db_name | |
truncate django_content_type RESTART IDENTITY CASCADE; | |
```` | |
Finally: | |
``` | |
./manage.py loaddata dump.json | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment