Skip to content

Instantly share code, notes, and snippets.

@tbrlpld
Created March 11, 2023 23:37
Show Gist options
  • Save tbrlpld/05cbee4dbceec245d759dd0acf2126d5 to your computer and use it in GitHub Desktop.
Save tbrlpld/05cbee4dbceec245d759dd0acf2126d5 to your computer and use it in GitHub Desktop.
Transfer Django PostgreSQL to SQLite
# Bash "strict mode"
set -euo pipefail
IFS=$'\n\t'
echo "Transfer data from PostgreSQL to SQLite"
DUMP_FILE=$DB_DIR/dbdump.json
echo "Migrate SQLite database..."
USE_SQLITE=true ./manage.py migrate --no-input
echo "Flush SQLite database to remove data created during migrations..."
USE_SQLITE=true ./manage.py flush --no-input
echo "Dump PostgreSQL database..."
./manage.py dumpdata --natural-foreign --natural-primary --exclude "wagtailcore.PageLogEntry" --indent 4 > $DUMP_FILE
echo "Load database dump into SQLite..."
USE_SQLITE=true ./manage.py loaddata $DUMP_FILE
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment