From 123c4d59d921c8548a60fcb7f4996cd3c53828ba Mon Sep 17 00:00:00 2001 From: iotmani Date: Wed, 3 Oct 2018 12:33:15 -0400 Subject: [PATCH 1/2] Fix for error when missing MySQLdb --- appengine/standard_python37/django/mysite/settings.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/appengine/standard_python37/django/mysite/settings.py b/appengine/standard_python37/django/mysite/settings.py index 059d3a484f1..77cb00a1efd 100644 --- a/appengine/standard_python37/django/mysite/settings.py +++ b/appengine/standard_python37/django/mysite/settings.py @@ -79,6 +79,16 @@ # Database # https://docs.djangoproject.com/en/2.1/ref/settings/#databases +# Check to see if MySQLdb is available; if not, have pymysql masquerade as +# MySQLdb. This is a convenience feature for developers who cannot install +# MySQLdb locally; when running in production on Google App Engine Standard +# Environment, MySQLdb will be used. +try: + import MySQLdb # noqa: F401 +except ImportError: + import pymysql + pymysql.install_as_MySQLdb() + # [START db_setup] if os.getenv('GAE_APPLICATION', None): # Running on production App Engine, so connect to Google Cloud SQL using From 1d20d183cc2d7704d0a8c7dc2e790c71e6a2a015 Mon Sep 17 00:00:00 2001 From: iotmani Date: Wed, 3 Oct 2018 15:25:22 -0400 Subject: [PATCH 2/2] Database name missing for on production Name added as per the instructions in: https://cloud.google.com/python/django/appengine#configure_the_database_settings Note that this is a descrepancy compared to [python2 example](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/appengine/standard/django/mysite/settings.py#L113): 'NAME': 'polls', --- appengine/standard_python37/django/mysite/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/appengine/standard_python37/django/mysite/settings.py b/appengine/standard_python37/django/mysite/settings.py index 77cb00a1efd..f5e82a8147a 100644 --- a/appengine/standard_python37/django/mysite/settings.py +++ b/appengine/standard_python37/django/mysite/settings.py @@ -97,6 +97,7 @@ 'default': { 'ENGINE': 'django.db.backends.mysql', 'HOST': '/cloudsql/[YOUR-CONNECTION-NAME]', + 'NAME': '[YOUR-DATABASE]', 'USER': '[YOUR-USERNAME]', 'PASSWORD': '[YOUR-PASSWORD]', }