Why aren't my tables available during Django unitests?
Question: When I try to run my unittests, I'm getting an error that says a table is not
available in the database. My tests were running fine a day ago, and a
brainstorm around what I've changed since then isn't bringing to mind anything
that gets close to causing this issue.

I'm seeing this as a problem with `syncdb` and `South` not creating the table
properly in the `sqlite` database, and have tried to troubleshoot around that.

## Error message with traceback

    
    
    $ ./manage.py test --settings=settings.test -v2
    
    Creating test database for alias 'default' (':memory:')...
    Syncing...
    Creating tables ...
    Creating table django_admin_log
    Creating table auth_permission
    Creating table auth_group_permissions
    Creating table auth_group
    Creating table django_content_type
    Creating table django_session
    Creating table django_site
    Creating table south_migrationhistory
    Installing custom SQL ...
    Installing indexes ...
    
    Synced:
     > grappelli
     > django.contrib.admin
     > django.contrib.admindocs
     > django.contrib.auth
     > django.contrib.contenttypes
     > django.contrib.messages
     > django.contrib.sessions
     > django.contrib.sites
     > django.contrib.staticfiles
     > crispy_forms
     > floppyforms
     > south
     > subdomains
     > widget_tweaks
    
    Not synced (use migrations):
     - apps.application
     - apps.app_app
     - apps.accounts
     - apps.rampup
     - apps.students
     - apps.automated_responses
    (use ./manage.py migrate to migrate these)
    
    ======================================================================
    ERROR: test_can_save_form_with_clean_passwords (apps.accounts.tests.test_admin.TestCreateUserForm)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/chaz/dev/projects/si/apps/accounts/tests/test_admin.py", line 17, in setUp
        self.user = SIDummyUserFactory.create()
      File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/factory/base.py", line 452, in create
        attrs = cls.attributes(create=True, extra=kwargs)
      File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/factory/base.py", line 316, in attributes
        force_sequence=force_sequence,
      File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/factory/containers.py", line 263, in build
        sequence = self.factory._generate_next_sequence()
      File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/factory/base.py", line 287, in _generate_next_sequence
        cls._next_sequence = cls._setup_next_sequence()
      File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/factory/django.py", line 71, in _setup_next_sequence
        ).order_by('-pk')[0]
      File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/django/db/models/query.py", line 231, in __getitem__
        return list(qs)[0]
      File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/django/db/models/query.py", line 108, in __len__
        self._result_cache.extend(self._iter)
      File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/django/db/models/query.py", line 1140, in iterator
        for row in self.query.get_compiler(self.db).results_iter():
      File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 775, in results_iter
        for rows in self.execute_sql(MULTI):
      File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 840, in execute_sql
        cursor.execute(sql, params)
      File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 366, in execute
        six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2])
      File "/Users/chaz/dev/envs/startupinst/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 362, in execute
        return Database.Cursor.execute(self, query, params)
    DatabaseError: no such table: accounts_siuser
    

## Relevent settings

### INSTALLED_APPS

    
    
    In [2]: settings.INSTALLED_APPS  
    Out[2]:
    ('grappelli',  
     'django.contrib.admin',  
     'django.contrib.admindocs',  
     'django.contrib.auth',  
     'django.contrib.contenttypes',  
     'django.contrib.messages',  
     'django.contrib.sessions',  
     'django.contrib.sites',  
     'django.contrib.staticfiles',  
     'crispy_forms',  
     'floppyforms',  
     'south',  
     'subdomains',  
     'widget_tweaks',  
     'gunicorn',  
     'apps.application',  
     'apps.app_app',  
     'apps.automated_responses',  
     'apps.accounts',  
     'apps.rampup',  
     'apps.students',  
     'utils.context_processors',  
     'discover_runner')  
    

### `pip freeze --local`

    
    
     Django==1.5.4  
     Pygments==1.6  
     South==0.7.6  
     argparse==1.2.1  
     bpython==0.12  
     coverage==3.6  
     dj-database-url==0.2.1  
     django-braces==1.2.2  
     django-crispy-forms==1.2.2  
     django-debug-toolbar==0.9.4  
     django-discover-runner==0.4  
     django-filepicker==0.1.4  
     django-floppyforms==1.1  
     django-grappelli==2.4.4  
     django-parsley==0.0.2a0  
     django-subdomains==2.0.1  
     django-templated-email==0.4.7  
     django-widget-tweaks==1.1.2  
     envoy==0.0.2  
     factory-boy==2.1.1  
     gunicorn==0.16.1  
     ipdb==0.7  
     ipython==0.13.2  
     psycopg2==2.4.5  
     pytz==2013b  
     requests==2.0.0  
     simplejson==3.3.1  
     six==1.4.1  
     stripe==1.7.7  
     zulip==0.2.1  
    

## settings/test.py

    
    
    """ Test settings and globals which allow us to write our tests locally."""
    from .common import *
    
    ########
    # APPS #
    ########
    INSTALLED_APPS += (
        'discover_runner',
    )
    
    #################
    # TEST SETTINGS #
    #################
    #TEST_RUNNER = 'django_pytest.test_runner.TestRunner'
    TEST_RUNNER = "discover_runner.DiscoverRunner"
    TEST_DISCOVER_TOP_LEVEL = PROJECT_ROOT
    TEST_DISCOVER_PATTERN = "test_*"
    SOUTH_TESTS_MIGRATE = False
    
    
    ###########################
    # IN MEMORY TEST DATABASE #
    ###########################
    
    DATABASES = {
        "default": {
            "ENGINE": "django.db.backends.sqlite3",
            "NAME": ":memory:",
        },
    }
    

## Similar SO questions that didn't solve the problem

  * [Does South foul up the Django test runner framework](http://stackoverflow.com/questions/6900007/does-south-foul-up-the-django-test-runner-framework)
  * [Disable South when running Django unit tests](http://stackoverflow.com/questions/5798446/disable-django-south-when-running-unit-tests)
  * [Missing table when running django unittest with sqlite2](http://stackoverflow.com/questions/7336130/missing-table-when-running-django-unittest-with-sqlite3)

## What I've tried so far

  * Running the tests on another branch, that wasn't changed during the time when this happened _Result: Getting the same exact error and trackback_
  * Blowing away my virtual environment and starting a new one  
_Result: No change_


Answer: I ended up removing `South` from my `settings/test.py` file*, and the database
was created properly. Would love to hear if anybody has any ideas about why
this was happening. The setting below should have disabled South, causing
Django's `syncdb` to create the proper tables.

    
    
    SOUTH_TESTS_MIGRATE = False  
    SOUTH_SKIP_TESTS = True
    

*I have settings files for each environment, so just put South in the ones that need it, instead of having it in the `base.py`, which is where they all inherit from.

