Django 1.4 on GAE: sqlite "ImportError: cannot import name utils"
Question: I'm trying to get sqlite3 support working on Django 1.4 on Google App Engine
1.7.4 on Python 2.7.

I fiddled around with the "Google Cloud SQL" database backend, all worked well
(syncdb, insert/update/delete, ...).

But then I enabled sqlite (as Google Cloud SQL is slow when on localhost):

    
    
    import os
    if (os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine') or
        os.getenv('SETTINGS_MODE') == 'pushtolive'):
        # Running on production App Engine, so use a Google Cloud SQL database.
        DATABASES = {
            'default': {
                'ENGINE': 'google.appengine.ext.django.backends.rdbms',
                'INSTANCE': 'xyz:xyz',
                'NAME': 'my_database',
            }
        }
    else:
        # Running in development, so use a local SQLite database
        DATABASES = {
            'default': {
                'ENGINE': 'django.db.backends.sqlite3',
                'NAME': '/tmp/mysite.db',
            }
        }
    

and when I open any url (e.g. 127.0.0.1:8080) then I run into [this monstrous
stack
trace](https://gist.github.com/raw/4405464/76f6a6c31fb56d54bc8e9668ddea40d508ea714c/sqlite.traceback).
I stripped down the stack trace so it's more readable:

    
    
    ERROR    2012-12-29 09:07:06,223 base.py:215] Internal Server Error: /favicon.ico
    Traceback (most recent call last):
      File "/Users/philipp/python/mysite/urls.py", line 4, in <module>
        from django.contrib import admin
      File ".../google_appengine/lib/django_1_4/django/contrib/admin/__init__.py", line 3, in <module>
        from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
      File ".../google_appengine/lib/django_1_4/django/contrib/admin/helpers.py", line 2, in <module>
        from django.contrib.admin.util import (flatten_fieldsets, lookup_field,
      File ".../google_appengine/lib/django_1_4/django/contrib/admin/util.py", line 1, in <module>
        from django.db import models
      File ".../google_appengine/lib/django_1_4/django/db/__init__.py", line 40, in <module>
        backend = load_backend(connection.settings_dict['ENGINE'])
      File ".../google_appengine/lib/django_1_4/django/db/__init__.py", line 34, in __getattr__
        return getattr(connections[DEFAULT_DB_ALIAS], item)
      File ".../google_appengine/lib/django_1_4/django/db/utils.py", line 92, in __getitem__
        backend = load_backend(db['ENGINE'])
      File ".../google_appengine/lib/django_1_4/django/db/utils.py", line 24, in load_backend
        return import_module('.base', backend_name)
      File ".../google_appengine/lib/django_1_4/django/utils/importlib.py", line 35, in import_module
        __import__(name)
      File ".../google_appengine/lib/django_1_4/django/db/backends/sqlite3/base.py", line 14, in <module>
        from django.db import utils
    ImportError: cannot import name utils
    

From the stack trace I read that the execution runs to the `django.db.utils`
module, then into `django.db.backends.sqlite3.base`, then it tries to jump
into `django.db.utils` again but that then strangely fails.

The problem seems to be in the GAE environment, since this works:

    
    
    python mysite/manage.py syncdb
    

And this as well:

    
    
    python mysite/manage.py shell
    >>> from django.contrib.auth.models import User
    >>> u = User(username="hans")
    >>> u.save()
    >>> User.objects.all()
    [<User: hans>]
    

**What I tried so far:**

  * switched from/to Django 1.3/1.4
  * [uninstalled GAE](http://stackoverflow.com/questions/9189054/how-do-i-uninstall-google-app-engine-sdk#answer-14081488), installed it again
  * I tried through all the solutions google reveals for "ImportError from django.db import utils"
  * there is [this similar question](http://stackoverflow.com/questions/7866256). I tried executing the statements in the question and I don't run into the problem.

I'm on OS X 10.8.2 My PYTHONPATH is
`:/usr/local/google_appengine:/usr/local/google_appengine/lib/django_1_4`


Answer: As it's [not good practice to use sqlite in dev and mysql (as used by Cloud
SQL) in production](http://stackoverflow.com/questions/2306048/django-sqlite-
for-dev-mysql-for-prod) I don't recommend this setup to anyone.

Then, there is the option `--use_sqlite`: This is used to speed up development
when using the Google Data*store*. There is no similar option for Cloud SQL.

