5

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.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
steadynappin
  • 409
  • 3
  • 14
  • Can you add some more details about where you're trying to deploy this? App Engine Standard or Flex? How do you have it configured to find your database? – Dustin Ingram Sep 06 '18 at 16:15
  • its flex! i followed [this guide](https://codeburst.io/beginners-guide-to-deploying-a-django-postgresql-project-on-google-cloud-s-flexible-app-engine-e3357b601b91) ... so it deployed with a 'app.yaml' file configured correctly, as far as i can tell. will add more code in the original post though. (let me know what else i can tell you though!) – steadynappin Sep 06 '18 at 16:26
  • Have you tried setting the host/port/name/user/password directly rather than getting them from the environment? See https://cloud.google.com/python/django/flexible-environment and https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/appengine/flexible/django_cloudsql/mysite/settings.py – Dustin Ingram Sep 06 '18 at 16:48
  • nah good idea i will try that! would it throw that error if it's not connecting though? – steadynappin Sep 06 '18 at 16:58
  • @steadynappin In SO you should not add SOLVED or similar to indicate that you have solved your problem, just publish a response and mark it as correct. I recommend you check the [tour] – eyllanesc Sep 08 '18 at 02:16

1 Answers1

7

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.

steadynappin
  • 409
  • 3
  • 14