Jesper R
Jesper R

Reputation: 125

Django Database engine on Google app engine

I have some problems by trying to change my database engine on my app engine.

right now i use the "google.appengine.ext.django.backends.rdbms" and it works fine, but it's running slow.

What is the difference in using:

"google.appengine.ext.django.backends.rdbms" or "django.db.backends.mysql"

i have the following in my settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'google.appengine.ext.django.backends.rdbms',
        'INSTANCE': 'xenon-notch-461:madplanuge',
        'NAME': 'madplanuge',
    }
}

And when i try to change the database engine to:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'HOST': '/cloudsql/xenon-notch-461:madplanuge',
        'NAME': 'madplanuge',
        'USER': 'root',
    }
}

I get at server error on my appengine and the logs from the appengine says:

Traceback (most recent call last):

  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 267, in Handle
    result = handler(dict(self._environ), self._StartResponse)
  File "/base/data/home/apps/s~xenon-notch-461/2.382413358316680585/libs/django/core/handlers/wsgi.py", line 236, in __call__
    self.load_middleware()
  File "/base/data/home/apps/s~xenon-notch-461/2.382413358316680585/libs/django/core/handlers/base.py", line 49, in load_middleware
    mod = import_module(mw_module)
  File "/base/data/home/apps/s~xenon-notch-461/2.382413358316680585/libs/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/base/data/home/apps/s~xenon-notch-461/2.382413358316680585/libs/django/contrib/auth/middleware.py", line 3, in <module>
    from django.contrib.auth.backends import RemoteUserBackend
  File "/base/data/home/apps/s~xenon-notch-461/2.382413358316680585/libs/django/contrib/auth/backends.py", line 3, in <module>
    from django.contrib.auth.models import Permission
  File "/base/data/home/apps/s~xenon-notch-461/2.382413358316680585/libs/django/contrib/auth/models.py", line 8, in <module>
    from django.db import models
  File "/base/data/home/apps/s~xenon-notch-461/2.382413358316680585/libs/django/db/__init__.py", line 40, in <module>
    backend = load_backend(connection.settings_dict['ENGINE'])
  File "/base/data/home/apps/s~xenon-notch-461/2.382413358316680585/libs/django/db/__init__.py", line 34, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/base/data/home/apps/s~xenon-notch-461/2.382413358316680585/libs/django/db/utils.py", line 93, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/base/data/home/apps/s~xenon-notch-461/2.382413358316680585/libs/django/db/utils.py", line 27, in load_backend
    return import_module('.base', backend_name)
  File "/base/data/home/apps/s~xenon-notch-461/2.382413358316680585/libs/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/base/data/home/apps/s~xenon-notch-461/2.382413358316680585/libs/django/db/backends/mysql/base.py", line 17, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
ImproperlyConfigured: Error loading MySQLdb module: this is MySQLdb version (1, 2, 5, 'final', 1), but _mysql is version (1, 2, 4, 'beta', 4)

Upvotes: 0

Views: 274

Answers (1)

pgiecek
pgiecek

Reputation: 8240

When to use either module depends on your environment. You can find more details on how to use alternate databases for your working environments in App Engine documentation.

Basically, the django.db.backends.mysql module enables a Django app running in production to communicate with a production Google Cloud SQL instance.

On the other hand the google.appengine.ext.django.backends.rdbms backend is used when running on a developer workstation and accessing a production Cloud SQL instance.

An excerpt from the above mentioned documentation.

  • Use the standard django.db.backends.mysql when running in production and accessing a production Google Cloud SQL instance.
  • Use the standard django.db.backends.mysql when running on a developer workstation and accessing a local MySQL instance. In this case, the application uses the system MySQLdb driver.
  • Use the custom backend google.appengine.ext.django.backends.rdbms when running on a developer workstation and accessing a production Cloud SQL instance.

And yes, the error seems to have something to do with the incorrect version of your MySQLdb module.

Upvotes: 2

Related Questions