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.

5
  • 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? Commented Sep 6, 2018 at 16:15
  • its flex! i followed this guide ... 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!) Commented Sep 6, 2018 at 16:26
  • Have you tried setting the host/port/name/user/password directly rather than getting them from the environment? See cloud.google.com/python/django/flexible-environment and github.com/GoogleCloudPlatform/python-docs-samples/blob/master/… Commented Sep 6, 2018 at 16:48
  • nah good idea i will try that! would it throw that error if it's not connecting though? Commented Sep 6, 2018 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 Commented Sep 8, 2018 at 2:16

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

How did you do create an instance?
Nevermind, fixed it by creating a database manually; stackoverflow.com/a/26373972/9878135

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.