3

I am trying to deploy a project with digital ocean. I followed the instructions found at https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04 Some of the important ones: I ran:

postgres=# CREATE DATABASE jobzumoDB;
CREATE DATABASE

then:

postgres=# CREATE USER admin WITH PASSWORD '123';
CREATE ROLE
postgres=# GRANT ALL PRIVILEGES ON DATABASE jobzumoDB  TO admin;
GRANT

set the following in settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'jobzumoDB',
        'USER':'admin',
        'PASSWORD':'123',
        'HOST':'localhost',
        'PORT':'',
    }

then tried to run:

 ~/jobzumo/manage.py makemigrations

and got:

 File "/home/justin/jobzumo/env/lib/python3.6/site-packages/psycopg2/__init__.py", line 126, in connect
        conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
    django.db.utils.OperationalError: FATAL:  database "jobzumoDB" does not exist

Two things:

ALLOWED_HOSTS = ['jobzumo.com', '142.93.184.125']

I have not yet connect jobzumo.com to digital ocean, but the IP address was copied from my droplet.

Also, I ran: pip install django gunicorn psycopg2 (from digitial ocean)

but a tutorial on youtube said it was very important to now install psycopg2-binary instead, however, I did not do this as the video was veering far from digital ocean's tutorial.

Thanks for any help, after starting to understand django I didn't think deploying would be this much of a headscratcher.

Justin
  • 1,329
  • 3
  • 16
  • 25
  • your database name is incorrect. check it – Debendra Feb 11 '20 at 20:18
  • 1
    one useful debugging step here would be to try to connect to the database manually via cli - you should be able to do it like so: `sudo -u postgres psql -d jobzumoDB -U admin -W 123` – nthall Feb 11 '20 at 20:18
  • @nthall returns `psql: FATAL: Peer authentication failed for user "admin"` – Justin Feb 11 '20 at 20:25
  • @nthall I started with a youtube tutorial where I created a user 'justin' and this 'admin' user for some reason so I feel I might have screwed up and should start from the beginning only trying to follow digital oceans resources – Justin Feb 11 '20 at 20:26
  • sorry - add `-h localhost` and try again – nthall Feb 11 '20 at 20:26
  • @nthall that actually got me `psql: FATAL: database "jobzumoDB" does not exist` – Justin Feb 11 '20 at 20:27
  • I thought `postgres=# CREATE DATABASE jobzumoDB;` returning `CREATE DATABASE` was confirmation that it worked lol – Justin Feb 11 '20 at 20:27
  • next thing to try imo would be `sudo -u postgres psql -c '\l'` to list all databases. – nthall Feb 11 '20 at 20:29
  • 1
    @nthall there it is listed as 'jobzumodb' not 'jobzumoDB'! After changing that in settings.py `makemigrations` worked without a problem. Thank you, you've been tremendously helpful. If I wanted to learn more do I just need to read into postgres db? These are all commands I am unfamiliar with. – Justin Feb 11 '20 at 20:36
  • @user3131132 i did a little research into *why* this happened, would appreciate it if you could vote & accept my answer :D – nthall Feb 12 '20 at 16:02
  • @nthall sorry had to go to work after I didn't respond yesterday – Justin Feb 12 '20 at 19:56

2 Answers2

5

Formalizing what we worked out in the comments as an answer, when you give postgres an unquoted string as an identifier, it forces it to lower-case. see this similar answer from pgsql-general mailing list. So the actual name of the database created by the command CREATE DATABASE jobzumoDB; is jobzumodb. to create a database named jobzumoDB it's necessary to use quotes, as in CREATE DATABASE "jobzumoDB";

nthall
  • 2,847
  • 1
  • 28
  • 36
0

Use:

NAME': 'jobzumodb',

Instead of:

NAME': 'jobzumoDB',