Skip to content

Instantly share code, notes, and snippets.

@Grace-Amondi
Last active September 9, 2022 23:41
Show Gist options
  • Save Grace-Amondi/fc6727c83332ba1ad7520ad04d438174 to your computer and use it in GitHub Desktop.
Save Grace-Amondi/fc6727c83332ba1ad7520ad04d438174 to your computer and use it in GitHub Desktop.

Migrate Django Database from SQLite to PostgreSQL

Backup all data in SQLITE

./manage.py dumpdata --exclude=contenttypes --natural-foreign --natural-primary > datadump.json 

Reconfigure Database settings

Change database setting to postgresql configurations replacing values correctly

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': '<DATABASE_NAME>',
        'USER': '<DATABASE_USER>',
        'PASSWORD': '<DATABASE_USER_PASSWORD>',
        'HOST': '<DATABASE_HOST>',
        'PORT': <DATABASE_PORT>,
    }
}

Migrate All Django Application models

./manage.py makemigrations
./manage.py migrate

Restore all data to PostgreSQL

./manage.py loaddata datadump.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment