将Django连接到Google Cloud SQL

编程入门 行业动态 更新时间:2024-10-25 08:25:48
本文介绍了将Django连接到Google Cloud SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将Django连接到Google云端SQL,在Windows下使用python 2.7和django 1.5。我浏览了此页面上的说明: 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: developers.google/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.

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

You can see the different configuration options here: developers.google/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

本文发布于:2023-10-23 23:04:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1522257.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   Django   Google   SQL   Cloud

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!