Thursday, September 17, 2020

Link postgres as backend database

 For that, we need a binding package.


pip install psycopg2 -->binding for postgres


And we need to create a database to refer.Lets say portfoliodb.

On postgres commandline:

create database portfoliodb;

\1

\q


In the project root folder, add below content to settings.py by commenting the existing lines for sqllite.


settings.py

---

DATABASES = {

  'default':{

    'ENGINE': 'django.db.backends.postgresql',

    'NAME': 'portfoliodb',

    'USER': 'postgres',

    'PASSWORD': '',

    'HOST': 'localhost',

     'PORT': '5432',

 }

}


to import the existing data created by django like user authentication,etc to database.Use below command.

python manage.py makemigrations

python manage.py migrate


To check the database of Postgres with commandline.

psql cmds:

\c portfoliodb

\dt


No comments:

Post a Comment