Connect Django with PostgreSQL

PAUL OLUYEMI
PAUL OLUYEMI
339 بار بازدید - پارسال - To connect Django with PostgreSQL,
To connect Django with PostgreSQL, you can follow these steps:

1. Install the psycopg2 package using pipenv:
       
       pipenv install psycopg2-binary
2. Configure your Django project to use PostgreSQL by modifying the DATABASES setting in the settings.py file:

DATABASES = {
   'default': {
       'ENGINE': 'django.db.backends.postgresql',
       'NAME': 'mydb',
       'USER': 'myuser',
       'PASSWORD': 'mypassword',
       'HOST': 'localhost',
       'PORT': '5432',
   }
}
Replace mydb, myuser, and mypassword with the name of your PostgreSQL database, the username you created, and the password you set for the user, respectively. The HOST and PORT values should be set to the location and port number of your PostgreSQL server.

3. Run the Django migrations to create the necessary database tables:

python manage.py migrate
If everything is configured correctly, Django will use the PostgreSQL database as the default database backend. You can now use Django's ORM to interact with the database and perform CRUD operations.
پارسال در تاریخ 1402/02/17 منتشر شده است.
339 بـار بازدید شده
... بیشتر