vendredi 14 novembre 2014

python - Django sur Google AppEngine avec CloudSQL : comment connecter une base de données (erreur 2002, impossible de se connecter à local MySQL server...) - Stack Overflow


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..?)



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..?)


0 commentaires:

Enregistrer un commentaire