Django Official Tutorial Setting Up PostgreSQL

I am on the django tutorial trying to have PostgressSQL be the database provided for my Django Project. After researching on Youtube, Looking in StackOverflow, and Asking Chat CPT I have come up empty. Per chat GPT I am supposed to install postgress. which I have run the installer and done fully. When I run pip install psycopg2 it says the requirement is already satisfied. In my Django Project I have opened settings.py in the projects main directory and located the databases section. I replaced the code with the code for postgress.

DATABASES = {
‘default’: {
‘ENGINE’: ‘django.db.backends.postgresql’,
‘NAME’: ‘your_database_name’,
‘USER’: ‘your_username’,
‘PASSWORD’: ‘your_password’,
‘HOST’: ‘localhost’,
‘PORT’: ‘5432’, # default PostgreSQL port
}
}

I have replaced ‘your_database_name’, ‘your_username’, and ‘your_password’ with my actual database name, username, and password, respectively.

When I try to do step 4 which is create the database I try running the command

createdb your_database_name

I make sure to replace ‘your_database-name’ with the actual name I specified in the ‘settings.py’ file.

I get the following error message. zsh: command not found: createdb.

any advice?

Hi @strikeouts27
on linux you have to do on your terminal

  • sudo su postgres
  • Then write psql
  • Then create your database like this
    CREATE DATABASE MYDBNAME;

and don’t forget the semicolon “;”
That’s all …

Also it is good to use (DBEAVER) to open any database on linux or if you use vscode try to install (PostgreSQL) extension by “Weijan Chen” it is so helpful.
But if you like Terminal as I do it’s good and terminal will help you to understand the postgreSQL command quickly

Hope it helps …

I use visual studio code on my MacBook if that changes anything. I will be certain to check out that extension that you mentioned is there a difference if I use a MacBook or a way I can look it up

PostgreSQL command is the same on all platforms but the reach to it is different on each platform (i.e CREATE DATABASE, DROP DATABASE and etc.) are the same depending only on the postgreSQL version you use.

I’m using (psql (15.2 (Debian 15.2-2)))
I think (CREATE DATABASE) command is from (psql (9))
You can review PostgreSQL Docs
PostgreSQL Docs

Why not using Docker ?
example: