1

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]
}

And this code

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]
}

And this is the error:

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 

I need your help, please.

The Django version is 1.5 is very old


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]
}

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.

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.

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

Daniel Ocando
  • 3,554
  • 2
  • 11
  • 19

1 Answers1

1

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.

Daniel Ocando
  • 3,554
  • 2
  • 11
  • 19
  • Thanks, this is exactly that I wrote in the second try, with 'django.db.backends.mysql' but other error appears AttributeError at / 'module' object has no attribute 'FOUND_ROWS' exist other ENGINE what I could try? – Daniel Robles Nov 27 '19 at 17:30
  • You basically just need to follow this [section](https://cloud.google.com/sql/docs/mysql/connect-app-engine) of the documentation. Assuming that the Cloud SQL instance (Cloud SQL Admin API connected) and App Engine (the service account has at least the Cloud SQL Client role assigned) are properly set up, you basically just need to import the [sqlalchemy library](https://www.sqlalchemy.org/library.html) and use the [´create_engine()´ method](https://docs.sqlalchemy.org/en/13/core/engines.html) to connect to your instance using the Unix domain socket. – Daniel Ocando Nov 27 '19 at 20:27