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.

2
  • I also tested with the IP address in the INSTANCE field, but is a invalid instance name Commented Oct 31, 2019 at 22:17
  • The enviroment is the Standard App Engine and the SQL is the Second Generation, I think that the connection is not possible, ;-( Commented Oct 31, 2019 at 23:45

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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?
You basically just need to follow this section 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 and use the ´create_engine()´ method to connect to your instance using the Unix domain socket.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.