Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Eduard-gan/3147d3f3159300443533849ff4fbadbf to your computer and use it in GitHub Desktop.
Save Eduard-gan/3147d3f3159300443533849ff4fbadbf to your computer and use it in GitHub Desktop.
Move Django project from Sqlite to Postgres
# 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