6. Model and PostgreSQL in Django



6. Model and PostgreSQL in Django

6. Model and PostgreSQL in Django

This video will demonstrate the use of models and postgresql demonstration.
Steps:
1. install postgresql (https://www.postgresql.org/download/)
2. install pgadmin4 (Default comes with postgresql if not download separately )
3. install psycopg2
type: pip install psycopg2 OR pip install psycopg2-binary
4. Create model class
class Product(models.Model):
product_name = models.CharField(max_length=100,unique=True, default=”)
product_desc = models.CharField(max_length=100,unique=True, default=”)
product_price = models.IntegerField()
class Meta:
pass
5. add database in pg admin
create database
6. add databse in setting.py
‘ENGINE’: ‘django.db.backends.postgresql’,
‘NAME’: ‘YOUR_DB_NAME’,
‘USER’: ‘postgres’,
‘PASSWORD’: ‘1234’,
‘HOST’ : ‘localhost’
7. add installed app in setting.py
INSTALLED_APPS = [
‘YOUR_APP’,
]
8. Type command
python manage.py makemigrations
9. Type command
python manage.py migrate
10. check in pgadmin whether table is created or not