diff --git a/appengine/standard_python37/django/mysite/settings.py b/appengine/standard_python37/django/mysite/settings.py index 059d3a484f1..f5e82a8147a 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 @@ -87,6 +97,7 @@ 'default': { 'ENGINE': 'django.db.backends.mysql', 'HOST': '/cloudsql/[YOUR-CONNECTION-NAME]', + 'NAME': '[YOUR-DATABASE]', 'USER': '[YOUR-USERNAME]', 'PASSWORD': '[YOUR-PASSWORD]', }