简体   繁体   English

在开发环境中使用Cloud SQL的Google App Engine上的Django

[英]Django on Google App Engine with Cloud SQL in dev environment

I am trying to create an application with Django on GAE and CloudSQL as the db. 我正在尝试使用Django在GAE和CloudSQL上创建一个应用程序作为数据库。
I used this google developers link and this link for setting up the dev-environment. 我使用这个谷歌开发人员链接这个链接来设置开发环境。 I am not able to connect to local mysql db. 我无法连接到本地mysql数据库。

Here is the DATABASE setting which I am trying to use. 这是我正在尝试使用的DATABASE设置。

if (os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine') or
os.getenv('SETTINGS_MODE') == 'prod'):
DATABASES = {
    'default': {
        'ENGINE': 'google.appengine.ext.django.backends.rdbms',
        'INSTANCE': 'instance:appid',
        'NAME': 'database_name',
    }
}
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'USER': 'root',
            'PASSWORD': '',
            'HOST': 'localhost',
            'NAME': 'database_name',
        }
    }

My app is working perfectly on production GAE, but when I try to start the app on dev env, I am getting this error 我的应用程序完全适用于生产GAE,但当我尝试在dev env上启动应用程序时,我收到此错误

File "/home/sandeep/Downloads/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 635, in __init__
raise IOError(errno.EACCES, 'file not accessible', filename)
IOError: [Errno 13] file not accessible: '/usr/local/lib/python2.7/site-packages/MySQL_python-1.2.4-py2.7-linux-x86_64.egg'

Complete stack-trace at http://pastebin.com/ZXHv0FPQ http://pastebin.com/ZXHv0FPQ上完成堆栈跟踪

I had installed the "python-mysql" by downloading the source and running "python setup.py install" 我通过下载源并运行“python setup.py install”安装了“python-mysql”

Edit 1 编辑1
I have also tried adding the MySQLdb to the library. 我也尝试将MySQLdb添加到库中。

- name: MySQLdb
  version: "latest"

Got this error 得到了这个错误

the library "MySQLdb" is not supported
  in "/home/sandeep/development/UploadImage/src/app.yaml", line 14, column 1

EDIT 2 编辑2
Django syncdb is working fine with this settings and django is able to create the tables for me.But,when I try to run via "dev_appserver.py", then I got the above stacktrace. Django syncdb在这个设置下运行正常,django能够为我创建表。但是,当我尝试通过“dev_appserver.py”运行时,我得到了上面的堆栈跟踪。
I am able to access the cloudSQL in dev environment. 我可以在开发环境中访问cloudSQL。

This should work as mentioned here . 这应该像这里提到的那样工作。 I don't there is anything wrong with this code snippet. 我没有这个代码片段有什么问题。

import os
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'):
    # Running on production App Engine, so use a Google Cloud SQL database.
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'HOST': '/cloudsql/your-project-id:your-instance-name',
            'NAME': 'django_test',
            'USER': 'root',
        }
    }
elif os.getenv('SETTINGS_MODE') == 'prod':
    # Running in development, but want to access the Google Cloud SQL instance
    # in production.
    DATABASES = {
        'default': {
            'ENGINE': 'google.appengine.ext.django.backends.rdbms',
            'INSTANCE': 'your-project-id:your-instance-name',
            'NAME': 'django_test',
            'USER': 'root',
        }
    }
else:
    # Running in development, so use a local MySQL database.
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'django_test',
            'USER': 'root',
            'PASSWORD': 'root',
        }
    }

I have also been using Google App Engine with cloudsql in django and here are the settings that I have been using for deployment and local development and it works just fine !! 我也一直在django中使用带有cloudsql的Google App Engine,这里是我一直用于部署和本地开发的设置,它工作得很好!!

Settings for deployment in GAE 在GAE中部署的设置

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', 
        'HOST': '/cloudsql/instance:appid',
        'NAME': 'name_of_database',
        'USER': 'mysql_user',
    }
}

Settings for local development with App engine sdk 使用App引擎sdk进行本地开发的设置

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'name_of_database',
        'USER': 'mysql_user',
        'PASSWORD': 'pwd',
        'HOST': 'ip_address_of_cloudsql_instance',   # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Cloud SQL-操作系统环境未设置为Google App Engine - Google Cloud SQL - OS environment not set to Google App Engine Google App Engine 上的 Django 连接到云 SQL,无法连接 - Django on Google App Engine connection to Cloud SQL, cannot connect Google App Engine / Cloud SQL / Django syncdb数据库后端错误 - Google App Engine/Cloud SQL/Django syncdb database backend error Google App Engine-Google App Engine开发环境和应用程序环境有什么区别 - Google app engine - What is the different between google app engine dev environment and application environment Google Cloud App Engine 部署失败 (Django) - Google Cloud App Engine Deploy Fail (Django) Google App Engine 连接到 Cloud SQL postgres - Google App Engine connect to Cloud SQL postgres Google App Engine,Django:部署后未在Google Cloud SQL中创建表 - Google App Engine, Django: Tables are not made in Google cloud SQL after deployment Google Cloud App Engine:如何在灵活的环境中提供https - Google Cloud App Engine: How to serve https in a Flexible environment 如何将旧的 Django Google App Engine 应用程序升级到第二代云 SQL 实例? - How do I upgrade an old Django Google App Engine application to a Second Generation Cloud SQL Instance? 无法使用Django访问dev_appserver中的Google Cloud SQL实例 - Unable to access Google Cloud SQL instance in dev_appserver with Django
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM