将Django连接到Google Cloud SQL [英] Connect Django to Google Cloud SQL

查看:185
本文介绍了将Django连接到Google Cloud SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Django连接到Google云端SQL,在Windows下使用python 2.7和django 1.5。我浏览了此页面上的说明: https://developers.google。 com / appengine / docs / python / cloud-sql / django

I'm trying to connect Django to the Google cloud SQL, working with python 2.7 and django 1.5 under windows. I went through the instructions on this page: https://developers.google.com/appengine/docs/python/cloud-sql/django

我的settings.py文件具有以下形式的基本数据库设置:

My settings.py file has basic database settings of the form:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'INSTANCE': 'my_project:instance1',
        'NAME': 'my_database',
    }
}

当然可以通过google apis控制台的SQL提示符创建SQL实例和数据库

With of course a proper could SQL instance and a database created through the SQL prompt of the google apis console

当我第一次尝试运行 manage.py syncdb 以获取OAuth2令牌时,我得到:

When I try to run manage.py syncdb for the first time in order to obtain an OAuth2 token, I get this:


OperationalError:(2003,无法连接到本地主机上的MySQL服务器
(10061))

OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)")

在你之前问,我确实确定django和谷歌包都在我的PYTHONPATH,以及C:\Program Files(x86)\Google\google_appengine\lib\django-1.5

Before you ask, I did make sure that both the django and google packages are in my PYTHONPATH, as well as "C:\Program Files (x86)\Google\google_appengine\lib\django-1.5"

任何帮助将非常受欢迎!

Any help would be really welcome!

推荐答案

数据库配置只有在从AppEngine连接。如果要使用django从本地机器访问CloudSQL数据库,则应使用 google.appengine.ext.django.backends.rdbms 引擎。

That database configuration only makes sense when connecting from AppEngine. If you want to access your CloudSQL database from your local machine using django, you should use the google.appengine.ext.django.backends.rdbms engine.

您可以在此处查看不同的配置选项:
https://developers.google.com/appengine/docs/python/cloud-sql/django#development-settings

You can see the different configuration options here: https://developers.google.com/appengine/docs/python/cloud-sql/django#development-settings

编辑 google.appengine.ext.django.backends.rdbms 引擎已被弃用。如果要从本地计算机连接到Google Cloud SQL,则应使用IP连接。您可以使用Cloud SQL实例IP(IPv4或IPv6),并使用标准的 django.db.backends.mysql 引擎进行连接。

EDIT: The google.appengine.ext.django.backends.rdbms engine has been deprecated. If you want to connect to Google Cloud SQL from your local machine you should use IP connectivity. You can use the Cloud SQL instance IP (IPv4 or IPv6) and connect using the standard django.db.backends.mysql engine.

这篇关于将Django连接到Google Cloud SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆