2

当我尝试运行我的单元测试时,我收到一条错误消息,指出数据库中没有可用的表。一天前我的测试运行良好,围绕我从那时起所做的更改进行的头脑风暴并没有让人想起任何接近导致此问题的东西。

我认为这是一个问题,syncdb并且South没有在数据库中正确创建表sqlite,并试图解决这个问题。

带有回溯的错误消息

$ ./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

相关设置

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  

设置/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:",
    },
}

没有解决问题的类似 SO 问题

到目前为止我尝试过的

  • 在另一个分支上运行测试,在发生这种情况时没有更改 结果:得到相同的确切错误和引用
  • 吹走我的虚拟环境并开始一个新的
    结果:没有变化
4

1 回答 1

0

我最终South从我的settings/test.py文件中删除*,并且数据库已正确创建。很想听听是否有人对为什么会发生这种情况有任何想法。下面的设置应该禁用 South,导致 Djangosyncdb创建正确的表。

SOUTH_TESTS_MIGRATE = False  
SOUTH_SKIP_TESTS = True

*我有每个环境的设置文件,所以只需将 South 放在需要它的地方,而不是将它放在base.py它们都继承的地方。

于 2013-10-09T16:03:57.183 回答