1

I am using the following database settings

DATABASES = {
    'default': {
         'ENGINE': 'django.db.backends.sqlite3',
         'NAME': os.path.join(_DB_DIR, 'dev.db'),
         'TEST_NAME': os.path.join(_DB_DIR, 'dev_test.db'),
    }
}

However, every time I run python manage.py test it breaks. The problem seems to be on the test database. For some reason the same tables from the standard db are not being created over there. The command returns django.db.utils.DatabaseError: no such table: tbforms_userprofile . And indeed, when I open the dev_test.db using sqlite3 it's possible to see the specified table (and any other from the tbforms application) does not exist.

What am I missing? I'm using Django 1.4 with Sqlite

PS: Important to notice that syncdb and migrate run smoothly. The complete traceback is available here: http://pastebin.com/9dVmuVyt

Fernando Ferreira
  • 798
  • 1
  • 11
  • 26
  • 1
    Have you added tbforms to your project since adding South? If so, you may need to create initial migrations for the tbforms app. Or, just set [SOUTH_TESTS_MIGRATE](http://south.readthedocs.org/en/latest/settings.html#south-tests-migrate) to `False`. – Austin Phillips Aug 05 '13 at 05:42

1 Answers1

1

As we've discussed, the issue here is that there's a post save signal for the User model (which is created during syncdb) to create a Profile model (which is created after syncdb, at south's migrate). So, when syncdb (or your tests) creates the tables on a new database and creates a new user, the table for the user profile is not yet created and this error is raised.

Solutions:

  • Avoid the creation of this profile automatically at User creation (bad smells about it)
  • Use Django 1.5 and it's custom user model support
  • Disabling south for tests (SOUTH_TESTS_MIGRATE = False) and always creating new databases specifying syncdb --all then migrate --fake. (not the best solution, though)
  • Got the 3rd option as you know... But definitely I will migrate to Django 1.5 at some point. The user profile signal was created like it was pointed out here: http://stackoverflow.com/questions/1910359/creating-a-extended-user-profile – Fernando Ferreira Aug 05 '13 at 16:52