我猜这是一个相当简单的问题,但是我很难把我的django项目放到gae上。不访问我的云sql数据库的页面工作正常,但是每当我试图访问引用该数据库的页面时,我会得到OperationalError (2001, "Can't create UNIX socket (-1)")
所有其他问题似乎都有第24个或第12个错误,这似乎是不同的问题。
下面是一些相关的代码片段:
# settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'INSTANCE': '******:webapp',
'NAME': 'web_db',
'USER': 'root',
}
}
# views.py
def createUUID(request):
id = UUID.create(uuid.uuid4())
id.save() # Error happens here
return HttpResponse(id.uuid)
例外的全文:
OperationalError at /register/
(2001, "Can't create UNIX socket (-1)")
Request Method: GET
Request URL: http://*****.appspot.com/register/
Django Version: 1.5.4
Exception Type: OperationalError
Exception Value:
(2001, "Can't create UNIX socket (-1)")
Exception Location: /base/data/home/runtimes/python27/python27_lib/versions/third_party/MySQLdb-1.2.4b4/MySQLdb/connections.py in __init__, line 190
Python Executable: /base/data/home/runtimes/python27/python27_dist/python
Python Version: 2.7.5
Python Path:
['/base/data/home/apps/s~******/1.371736483116355711',
'/base/data/home/runtimes/python27/python27_dist/lib/python27.zip',
'/base/data/home/runtimes/python27/python27_dist/lib/python2.7',
'/base/data/home/runtimes/python27/python27_dist/lib/python2.7/plat-linux2',
'/base/data/home/runtimes/python27/python27_dist/lib/python2.7/lib-tk',
'/base/data/home/runtimes/python27/python27_dist/lib/python2.7/lib-old',
'/base/data/home/runtimes/python27/python27_dist/lib/python2.7/lib-dynload',
'/base/data/home/runtimes/python27/python27_dist/lib/python2.7/site-packages',
'/base/data/home/runtimes/python27/python27_lib/versions/1',
'/base/data/home/runtimes/python27/python27_lib/versions/third_party/MySQLdb-1.2.4b4',
'/base/data/home/runtimes/python27/python27_lib/versions/third_party/django-1.5',
'/base/data/home/runtimes/python27/python27_lib/versions/third_party/protorpc-1.0',
'/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3',
'/base/data/home/runtimes/python27/python27_lib/versions/third_party/webob-1.1.1',
'/base/data/home/runtimes/python27/python27_lib/versions/third_party/yaml-3.10',
u'/base/data/home/apps/s~*****/1.371736483116355711/..']
Server time: Tue, 19 Nov 2013 07:30:30 +0000
有什么见解吗?
最佳答案
高石的正确答案!
将主机设置更改为-'host':'/cloudsql/your project id:your instance name'
DATABASES = {
'default': {
'ENGINE':'django.db.backends.mysql',
'HOST':'/cloudsql/your-project-id:your-instance-name',
'NAME': 'db_name',
'USER': 'root',
'PASSWORD': '********',
}
被困在这里两天了!谢谢您!