SQLite to PostgreSQL - adityaskarnik/expense_app GitHub Wiki

Setup Postgres first:

deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main # for ubuntu 18.04
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
apt-get install postgresql-10

Once Installation is done setup postgres to login without always asking for password:

sudo vi /etc/postgresql/10/main/pg_hba.conf

Change this line (md5 to trust):

# Database administrative login by Unix domain socket
local   all             postgres                                trust

Run this command to apply the changes

sudo service postgresql restart

Inside postgres create your own user (if you want):

sudo -u postgres createuser <user_name> # create user
sudo -u postgres createdb <db_name> # create new database
	
# create a password to the user
sudo -u postgres psql
alter user expense with encrypted password '<password>';	

In your application, make changes to database:

python manage.py makemigrations
python manage.py migrate

Export SQLite data:

  1. Using csv, go here

  2. Export using application manage .py

    python manage.py dumpdata > dump_sqlite.json
    

    To convert your model changes to python code and apply them:

    python manage.py makemigrations
    python manage.py migrate
    

    Finally:

    python manage.py loaddata dump_sqlite.json
    
⚠️ **GitHub.com Fallback** ⚠️