4
votes

I'm trying to start a Django app to be hosted on GAE, using CloudSQL. Locally, I'm on Mac OSX Maverics, working within a virtualenv (via virtualenvwrapper).

After installing the GAE SDK for Python, I started my virtual environment, installed Django 1.5 from /usr/local/google_appengine/lib/django-1.5/

Also, on appengine.google.com I created a new app, and connected a CloudSQL instance to it (enable billing).

I'm able to create a new Django project, e.g. django-admin.py startproject test01, then I edit its settings.py to change the DATABASES definition per Google's instructions, e.g:

DATABASES = {
   'default': {
      'ENGINE': 'django.db.backends.mysql',
      'HOST': '/cloudsql/myapp-test01:myapp-db-test01',
      'NAME': 'test01',
      'USER': 'test01',
}

}

I also added app.yaml to the root of the project folder, per Google's docs:

application: test01
version: 1
runtime: python27
api_version: 1
threadsafe: true

libraries:
- name: django
  version: "1.5"

builtins:
- django_wsgi: on

This is where I hit roadblocks.

First: What exactly should be entered into the DATABASES for NAME and USER fields? The docs do not go into any detail.

Second, when I run: python manage.py syncdb to initialize the app, I get:

OperationalError: (2002, "Can't connect to local MySQL server through socket '/cloudsql/desgn-test-01:db-test-01' (2)") 

I do have MySQL installed, via brew install mysql (although I didn't do that inside the virtual environment), and I also have MySQL-python.

I'm new to GAE and fairly inexperienced with setting up databases, so I'm not sure what do try next. I'm not sure if the issue is with my local MySQL, or the CloudSQL connection settings?

(A more general Django on GAE question: What is the workflow exactly? If I get the connection to work, does it mean that I am using CloudSQL even when developing my Django app locally? How do I subsequently "push" the app to the AppEngine, or make updates? I'm assuming this is done with the Launcher but what is the correlation between creating (adding) an app using the appengine.google.com dashboard, versus adding a new app in the local launcher? Quite confused by this -- are these two one and the same app, need to have identical names, or..?)

1
Do not give the absolute path to the database name. It should be just the database name. 'HOST': '/cloudsql/myapp-test01:myapp-db-test01'karthikr
Not sure why you say the docs don't go into detail about the NAME and USER fields. On the contrary, they specify exactly what to put - and later on describe how to connect to a local db in development.Daniel Roseman
@Daniel: I read it but to me, being a beginner, it's not enough, hence my SO question. Is NAME the name I gave the DB on CloudSQL? So, in my case 'myapp-db-test01'? And for USER, I'm at a loss.. for PHP apps I'd do 'root' but what do I do for CloudSQL? There was no user specified during setup.. my Google ID??pete
@Karthikkr: Isn't what you are suggesting exactly what I have above?pete
"These values should correspond to the names you chose when creating your Google Cloud SQL instance and database."Daniel Roseman

1 Answers

0
votes

Looks like at the time, you were missing the password field as well...

    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'test01',
        'USER': 'test01',
        'PASSWORD': '[password]',
        'HOST': '/cloudsql/myapp-test01:myapp-db-test01',
        'PORT': '3306',
    }

Using the GUI for Cloud SQL, you can always add new Super Admin level users to the Cloud SQL instance in case you're unsure what user to use as well.