Django / Google Cloud: FATAL: database <db> does not exist / Server Error 500

Viewed 1117

i have a django app that runs fine locally but throws a server error 500 when i deploy it to google cloud. it's on a flex engine and i followed these very good instructions to set everything up.

it's telling me the database does not exist. (it does.)

SOLVED: i didn't realize there was a difference between an instance and a database. the instance existed but the database did not. i created the database in the instance and now everything works.

{
 insertId:  "s=81237568d9204e6081d81087faf41900;i=162cc;b=0ca68bbe363d49a581ec4e2fc6c45487;m=799aa9bfc;t=57529446a6708;x=4f176b686e1cb7ce-0@a1"  
 logName:  "projects/rcg-live/logs/cloudsql.googleapis.com%2Fpostgres.log"  
 receiveTimestamp:  "2018-09-06T00:49:51.309738251Z"  
 resource: {…}  
 severity:  "ALERT"  
 textPayload:  "FATAL:  database "rcg-live-db" does not exist"  
 timestamp:  "2018-09-06T00:49:45.486088Z"  
}

i get the same error when i try to connect the local app with cloud sql proxy tool:

Traceback (most recent call last):
  File "/anaconda3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
    self.connect()
  File "/anaconda3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 194, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/anaconda3/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 174, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/anaconda3/lib/python3.6/site-packages/psycopg2/__init__.py", line 130, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL:  database "rcg-live-db" does not exist

settings.py looks like this:

DATABASES = {
'default': {
  'ENGINE': 'django.db.backends.postgresql',
  'HOST': os.environ['DB_HOST'],
  'PORT': os.environ['DB_PORT'],
  'NAME': os.environ['DB_NAME'],
  'USER': os.environ['DB_USER'],
  'PASSWORD': os.environ['DB_PASSWORD']
}

}

and i'm p sure the app.yaml file is configured right ... it's finding the secret key and the debut setting responds when i change it, both are controlled by app.yaml

i'm not really sure what i can put here to show that a postgres database called 'rcg-live-db' exists on my cloud, so i guess take my word for it.

again, everything works locally, including the admin page. all 500 errors when i try to use the remote db.

1 Answers

SOLVED: i didn't realize there was a difference between an instance and a database.

the instance existed but the database did not.

i created the database in the instance and now everything works.

Related