migrate database from Sqlite3 to Postgres = Django

1k views Asked by At

I have a small app that I have build and I am planning on transfering it to a live environment. This app scales really quickly. I currently have Sqlite3 as the database stack I am using for my project. I wanted to know if it is smart for me to switch to PostgreSQL before I host my project in a live environment. My app is currently running through docker images and sqlite3 works find on docker, but I feel like later on when I am dealing with lots of requests, PostgreSQL would be better off for me. If it is a good idea to switch from sqlite3 to PostgreSQL, I know I have to do the following lines, but I am not sure what I have to change in the django settings python page...:

python manage.py dumpdata > dump.json

Change DB connection string in settings.py to POSTGRES

python manage.py syncdb
python manage.py loaddata data.json

login to postgres db using psql
- execute this to delete all the data in the content_types table truncate 
django_content_type RESTART IDENTITY CASCADE;

python manage.py loaddata data.json

So would the settings.py file look something like this compared to current setup:

current:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

modded:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgres',
        'NAME': os.path.join(BASE_DIR, 'db.postgres'),
    }
}

is that it for the changes that I have to do within the settings.py file. Do i need to add or change anything else...

Also how can I login to postgrs from within my django application locally....

0

There are 0 answers