2
votes

I have a django app hosted on google appengine and google cloud sql as database. I follows this link https://cloud.google.com/appengine/docs/python/cloud-sql/django to sync and migrate db schema to cloudsql. This worked fine for me. But when I tried syncdb today, I am getting an error as shown below.

OperationalError: could not connect: https://www.googleapis.com/sql/v1/jdbc/openConnection?alt=proto returned "Not Found">

My database settings is

    if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'):
        # Running on production App Engine, so use a Google Cloud SQL database.
        DATABASES = {
            'default': {
            'ENGINE': 'django.db.backends.mysql',
            'HOST': '/cloudsql/<projectname>:<instancename>',
            'NAME': '<db-name>',
            'USER': 'root',
            }
        }
    elif os.getenv('SETTINGS_MODE') == 'prod':
        # Running in development, but want to access the Google Cloud SQL instance in production.
        DATABASES = {
            'default': {
            'ENGINE': 'google.appengine.ext.django.backends.rdbms',
            'INSTANCE': '<projectname>:<instancename>',
            'NAME': 'db-name',
            'USER': 'root',
           }
        }
1

1 Answers

1
votes

I changed my db settings and authorized my local ip address at google api console. Now it is working fine.
My new db settings is

    if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'):
    # Running on production App Engine, so use a Google Cloud SQL database.
        DATABASES = {
        'default': {
        'ENGINE': 'django.db.backends.mysql',
        'HOST': '/cloudsql/<projectname>:<instancename>',
        'NAME': '<db-name>',
        'USER': 'root',
        }
    }
    elif os.getenv('SETTINGS_MODE') == 'prod':
    # Running in development, but want to access the Google Cloud SQL instance in production.
        DATABASES = {
        'default': {
        'ENGINE': 'django.db.backends.mysql',
        'HOST': '<instance-ip-address>',
        'NAME': 'db-name',
        'USER': 'root',
        'PASSWORD': '<password>'
       }
    }