8000 Enable PyMySQL as an option for local development. · johnmanong/python-docs-samples@90bfd6a · GitHub
[go: up one dir, main page]

Skip to content

Commit 90bfd6a

Browse files
committed
Enable PyMySQL as an option for local development.
1 parent d492a47 commit 90bfd6a
Copy full SHA for 90bfd6a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

appengine/standard/django/mysite/settings.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@
9292
# Database
9393
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
9494

95+
# Check to see if MySQLdb is available; if not, have pymysql masquerade as
96+
# MySQLdb. This is a convenience feature for developers who cannot install
97+
# MySQLdb locally; when running in production on Google App Engine Standard
98+
# Environment, MySQLdb will be used.
99+
try:
100+
import MySQLdb # noqa: F401
101+
except ImportError:
102+
import pymysql
103+
pymysql.install_as_MySQLdb()
104+
95105
# [START db_setup]
96106
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'):
97107
# Running on production App Engine, so connect to Google Cloud SQL using
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
MySQL-python==1.2.5
1+
PyMySQL==0.7.11
22
Django==1.11.6

0 commit comments

Comments
 (0)
0