将Google AppEngine Django与SQL第2代实例连接时出错? [英] Error connecting Google AppEngine Django with SQL 2nd generation instance?

查看:68
本文介绍了将Google AppEngine Django与SQL第2代实例连接时出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的站点从第一代Cloud SQL实例迁移到第二代,这是旧的配置:

I want to migrate my site from a First to a Second Generation Cloud SQL instance, this is the old config:

DATABASES['[DATABASE_NAME]'] = {
    'ENGINE': 'google.appengine.ext.django.backends.rdbms',
    'INSTANCE': '[PROJECT_ID]:[INSTANCE_ID_1stGEN]',
    'NAME': '[DATABASE_NAME]',
    'USER': [MY_USER],
    'PASSWORD': [MY_PASSWORD],
}

这工作正常,现在我正在尝试使用以下代码:

This works fine, now I'm trying with this code:

DATABASES['[DATABASE_NAME]'] = {
        'ENGINE': 'django.db.backends.mysql',
        'HOST': '/cloudsql/[PROJECT_NAME]:[REGION]:[INSTANCE_ID]',
        'NAME': '[DATABASE_NAME]',
        'USER': [MY_USER],
        'PASSWORD': [MY_PASSWORD]
}

此代码

DATABASES['[DATABASE_NAME]'] = {  # 2da gen no funciono error COUNT_ROWS
        'ENGINE': 'django.db.backends.mysql',
        'HOST': '[PROJECT_ID]:[REGION]:[INSTANCE_ID]',
        'NAME': '[DATABASE_NAME]',
        'USER': [MY_USER],
        'PASSWORD': [MY_PASSWORD]
}

这是错误:

AttributeError at /
'module' object has no attribute 'FOUND_ROWS'
   /base/alloc/tmpfs/dynamic_runtimes/python27g/79cfdbb680326abd/python27/python27_lib/versions/third_party/django-1.5/django/db/backends/mysql/base.py in _cursor
            kwargs['client_flag'] = CLIENT.FOUND_ROWS 

请帮助我.

Django版本1.5很旧

The Django version is 1.5 is very old

我发现一个错误,引擎是错误的,我用google.appengine.ext.django.backends.rdbms替换了它:

I found a error, the ENGINE is wrong, I replaced it with google.appengine.ext.django.backends.rdbms:

DATABASES['[DATABASE_NAME]'] = {
        'ENGINE': 'google.appengine.ext.django.backends.rdbms',
        'HOST': '/cloudsql/[PROJECT_ID]:[REGION]:[INSTANCE_ID]',
        'NAME': '[DATABASE_NAME]',
        'USER': [MY_USER],
        'PASSWORD': [MY_PASSWORD]
}

但是它仍然失败,现在它说需要一个INSTANCE密钥,然后我将INSTANCE替换为HOST:

but it still fails, now it says that an INSTANCE key is needed, then I replace HOST by INSTANCE:

DATABASES['[DATABASE_NAME]'] = {
        'ENGINE': 'google.appengine.ext.django.backends.rdbms',
        'INSTANCE': '/cloudsql/[PROJECT_ID]:[REGION]:[INSTANCE_ID]',
        'NAME': '[DATABASE_NAME]',
        'USER': [MY_USER],
        'PASSWORD': [MY_PASSWORD]
}

...什么都没有...

... nothing ...

DATABASES['[DATABASE_NAME]'] = {
        'ENGINE': 'google.appengine.ext.django.backends.rdbms',
        'INSTANCE': '[PROJECT_ID]:[REGION]:[INSTANCE_ID]',
        'NAME': '[DATABASE_NAME]',
        'USER': MY_USER,
        'PASSWORD':MY_PASSWORD
}

尝试此操作,现在又出现另一个错误:

trying this, and now another error:

InternalError at /
(0, u'Not authorized to access instance: [PROJECT_ID]:[REGION]:[INSTANCE_ID]')

/base/alloc/tmpfs/dynamic_runtimes/python27g/79cfdbb680326abd/python27/python27_lib/versions/1/google/storage/speckle/python/api/rdbms.py in MakeRequest
      request.request_id = self._idempotent_request_id
      response = self._MakeRetriableRequest(stub_method, request)
    else:
      response = self.MakeRequestImpl(stub_method, request)
    if (hasattr(response, 'sql_exception') and
        response.HasField('sql_exception')):
      raise _ToDbApiException(response.sql_exception) ...
    return response
  def _MakeRetriableRequest(self, stub_method, request):
    """Makes a retriable request.

添加SSL/TSL配置:

Adding SSL/TSL configuration:

DATABASES['[DATABASE_NAME]'] = {
            'ENGINE': 'google.appengine.ext.django.backends.rdbms',
            'INSTANCE': '[PROJECT_ID]:[REGION]:[INSTANCE_ID]',
            'NAME': '[DATABASE_NAME]',
            'USER': [MY_USER],
            'PASSWORD': [MY_PASSWORD],
            'OPTIONS': {'ssl': {
                'key': '/servidor/[INSTANCE_ID]/client-key.pem',
                'cert': '/servidor/[INSTANCE_ID]/client-cert.pem',
                'ca': '/servidor/[INSTANCE_ID]/client-ca.pem',
            }}

我仍然遇到相同的错误.

And I still get the same error.

证书正在运行,使用MySQL Workbench没问题.

The certificate is working, with MySQL Workbench there is no problem.

推荐答案

rdbms库不能与此处找到所有相关信息.

The rdbms library will not work with an upgraded Second Generation Cloud SQL instance as stated on the documentation. In order to connect to your Sencond Generation Cloud SQL instance to your App Engine Standard application please make sure that your service account has the correct permissions and use the Unix domain socket. All the relevant information can be found here.

这篇关于将Google AppEngine Django与SQL第2代实例连接时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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