Where Is Chile Located on a Map?

And how was I supposed to remember names I couldn’t pronounce when I was just trying to survive those awkward junior high years?! It wasn’t until I started to travel that maps came alive. But I could…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




What is PostgreSQL?

Connect Your Django Project with POSTGRES Database.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -

The Django framework comes into the picture when building web applications with Python. Django is a flexible framework that provides developers with outstanding features to create applications swiftly. Django applications are set by default to store data in a lightweight SQLite database file. This works effectively in some situations only.

Although Django has an SQLite3 database by default, developers prefer PostgreSQL over SQLite3 database files. Now you might consider why it is so. The main reason is PostgreSQL’s customized offering to tackle complex databases Django PostgreSQL integration can increase production performance.

If you are looking for steps to configure PostgreSQL Database with Django, then you landed in the right place. This guide will teach you how to integrate PostgreSQL with Django to use in your applications. In addition to that, it also walks through PostgreSQL and Django briefly.

PostgreSQL(also known as Postgres) is an open-source relational database that is adaptable to both SQL (relational) and JSON (non-relational). The PostgreSQL project began in 1986 at the University of California, Berkeley, under the guidance of Professor Michael Stonebreaker. The project was initially called POSTGRES, after the previous Ingres database, which was also created at Berkeley. POSTGRES sought to include only the capabilities required to handle different data types fully.

PostgreSQL supports transactions with Atomicity, Consistency, Isolation, and Durability (ACID) attribute and automatically updatable views, materialized views, triggers, foreign keys, and stored procedures.

The primary reasons to use Django PostgreSQL integration are mentioned below:

Now that you have a clear vision of the benefits in your mind, let’s walk past the steps required to establish the Django PostgreSQL connection. But first, let’s state some prerequisites.

Open your Command Line Interface(CLI) and create a project directory using the following command.

After creating the directory, the next step is to point towards the created directory with the following command.

In the Project development phase creating a virtual environment is a good practice. You can control the environment by segregating its environment from the rest of the systems.

The command to create a virtual environment is as follows:

The final step is to activate the virtual environment by running the command given below.

Now you have created a virtual environment for your project, so it’s time to install the required dependencies i.e., Django and PostgreSQL.

The above command will install the latest version of Django to your project.

Install the “psycopg2” module to get Python to operate with Postgres.

Let’s create our first project, which will only have one project in our project directory but will let us add as many applications as we need.

As a result of the above command, the “postgreTest” project folder will be generated in your project directory. You can verify the same in Visual Studio Editor.

Open up the project directory in Visual Studio and activate the virtual environment. Open the Visual Studio terminal and move to the project directory using the following command.

To launch your first app, use the following command.

Kudos to you for creating your first application in Django!

Now, try running the server to ensure that everything is working correctly. Run the following command in the visual studio terminal.

If everything is working correctly, you will get a link where your application is hosted on the local server. After clicking that link, you will land on the webpage shown below.

Create a database named “test” in your Postgres server using pgAdmin4.

It is now time to switch from the default database connection, i.e., SQLite3, to PostgreSQL in your Django project.

By default, you will find the lines of code that are shown below. This code is configuring Django with the default database(SQLite3).

You need to change the above settings to the parameters as shown below:

Run the following command to migrate all tables in our Django project to PostgreSQL.

You will get the output as shown below.

Congratulations!! You’ve successfully established the Django PostgreSQL connection.

Add a comment

Related posts:

Three Years Without You

I feel sad like I left you in the child drop box at the fire station.. “Three Years Without You” is published by Josh Shannonhouse.

Buy Google Reviews

Reviews are a big deal when you’re shopping online. And, if you’re going to pay for the item, you want to make sure you get what you paid for. Which is why it’s so important for sellers to have a…

If You are Planning to Make a Longer Trip to Lebanon

Lebanon has many places to stay, from luxury hotels to cozy chalets. Whether you’re traveling to Lebanon on business or for a family vacation, there are plenty of accommodations available to suit…