What are the steps I need to take to migrate from the default SQLite database to Postgres database?
I'm doing this to get my local development environment as close to my live server (which uses postrgres).
Or is there a reason why local development uses SQLite? Is it not recommended to use Postgres for local development?
You can try the following steps:
1. Install psycopg2 to configure the database:
pip install psycopg2
2. Inside the default settings.py
Change original values:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
To:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'NAME_OF_DB',
'USER': 'DB_USER_NAME',
'PASSWORD': 'DB_PASSWORD',
'HOST': 'localhost',
'PORT': 'PORT_NUMBER',
}
}
3. Migrate the DB:
python manage.py makemigrations
python manage.py migrate
Backup the data first:
python manage.py dumpdata > datadump.json
After changing the DB setting:
python manage.py loaddata datadump.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With