3

I have just started learning Django after I took some tutorials for Python.

I am trying to connect my POSTGRES database to the Django project I have just created.

However, I am experiencing this problem:

django.db.utils.OperationalError: FATAL:  database "producthuntdb" does not exist

I followed these steps:

1) Opened postgress by clicking its icon

2) Clicked on the database "postgress". The terminal opened and I wrote: CREATE DATABASE producthuntdb; The database has been created because I see it if I open postgress via its icon.

3) Went to my Django project in "settings" and change the SQLITE database to the following:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'producthuntdb',
        'USER': 'mymac2017',
        'PASSWORD': 'mypassword',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}

4) Run the code python3 manage.py migrate

However, I am getting the error:

django.db.utils.OperationalError: FATAL: database "producthuntdb" does not exist

So I did the following:

  • Cliking on postgress icon and opening the the database producthuntdb

  • Once the terminal is open, I wrote: \du

  • There are two users with the attributes:

    1) mymac2017 | Superuser, Create role, Create DB | {}

    2) postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

What am I doing wrong?

I tried to look other answers to this problem and most of the issues are from misspelling the database name OR not creating it. However, the name of my database is correct and I can see the database producthuntdb if I open postgres.

Many thanks for your help.

5
  • Does the user has access to the database? Commented Sep 13, 2018 at 16:27
  • I am sure about the database name. I am NOT sure how to check if the user has access to the database. I tried to click on "producthuntdb", and writre in the terminal "\du". There are two users, one of which is the same i wrote for "'USER': 'postgres'". Commented Sep 13, 2018 at 16:28
  • @WillemVanOnsem Wouldn't that raise an access denied error? Commented Sep 13, 2018 at 16:32
  • Did you try restart the postgresql service? Commented Sep 13, 2018 at 16:38
  • I tried to close and open again postgres (via clicking "quit") but I am not sure if it is what you mean, sorry. Commented Sep 13, 2018 at 16:41

1 Answer 1

4

I set the wrong port of the Database in the Django "settings.py".

I was using 'PORT': '5432' instead of 'PORT': '5433'

SOLUTION:

  • Go to your Postgres app/icon/program
  • Click on "Server setting" and see which PORT the database POSTGRES is using
  • Be sure that the PORT the database is using is the same as the one you write in the "settings.py" of your Django project.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.