Django 单元测试出现数据库错误 - 无法提交事务 - SQL 语句正在进行

发布于 2024-11-16 22:37:06 字数 5438 浏览 4 评论 0原文

我将 unittest2manage.py test 一起使用,在它似乎运行任何测试之前,它会抛出一个可怕的数据库错误,如下所示。我在我的开发环境中(实际上由于各种原因在 dreamhost 服务器上),使用 sqlite 作为我的数据库。

即使当我将应用程序从生产位置复制出来(并相应地编辑settings.py)时,我仍然会遇到相同的错误(即使它不应该再处理与开发环境相同的数据库文件)。

更新:即使将数据库文件的所有实例移至不同的文件名,仍然会出现相同的错误。这让我相信测试环境正在以某种方式查看伪造的数据库,或者正在发生一些非常奇怪的事情。

[graffias]$ python manage.py test
Creating test database for alias 'default'...
Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_manager(settings)
  File "/home/marcintustin/django/Django-1.3/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/home/marcintustin/django/Django-1.3/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/marcintustin/django/Django-1.3/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/marcintustin/django/Django-1.3/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/home/marcintustin/django/South-0.7.3-py2.5.egg/south/management/commands/test.py", line 8, in handle
    super(Command, self).handle(*args, **kwargs)
  File "/home/marcintustin/django/Django-1.3/django/core/management/commands/test.py", line 37, in handle
    failures = test_runner.run_tests(test_labels)
  File "/home/marcintustin/django/Django-1.3/django/test/simple.py", line 359, in run_tests
    old_config = self.setup_databases()
  File "/home/marcintustin/django/Django-1.3/django/test/simple.py", line 296, in setup_databases
    test_db_name = connection.creation.create_test_db(self.verbosity, autoclobber=not self.interactive)
  File "/home/marcintustin/django/Django-1.3/django/db/backends/creation.py", line 366, in create_test_db
    load_initial_data=False)
  File "/home/marcintustin/django/Django-1.3/django/core/management/__init__.py", line 166, in call_command
    return klass.execute(*args, **defaults)
  File "/home/marcintustin/django/Django-1.3/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/home/marcintustin/django/Django-1.3/django/core/management/base.py", line 351, in handle
    return self.handle_noargs(**options)
  File "/home/marcintustin/django/South-0.7.3-py2.5.egg/south/management/commands/syncdb.py", line 99, in handle_noargs
    management.call_command('migrate', **options)
  File "/home/marcintustin/django/Django-1.3/django/core/management/__init__.py", line 166, in call_command
    return klass.execute(*args, **defaults)
  File "/home/marcintustin/django/Django-1.3/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/home/marcintustin/django/South-0.7.3-py2.5.egg/south/management/commands/migrate.py", line 105, in handle
    ignore_ghosts = ignore_ghosts,
  File "/home/marcintustin/django/South-0.7.3-py2.5.egg/south/migration/__init__.py", line 191, in migrate_app
    success = migrator.migrate_many(target, workplan, database)
  File "/home/marcintustin/django/South-0.7.3-py2.5.egg/south/migration/migrators.py", line 221, in migrate_many
    result = migrator.__class__.migrate_many(migrator, target, migrations, database)
  File "/home/marcintustin/django/South-0.7.3-py2.5.egg/south/migration/migrators.py", line 298, in migrate_many
    interactive=self.interactive)
  File "/home/marcintustin/django/South-0.7.3-py2.5.egg/south/db/generic.py", line 808, in send_pending_create_signals
    interactive=interactive)
  File "/home/marcintustin/django/South-0.7.3-py2.5.egg/south/db/generic.py", line 855, in really_send_create_signal
    db=self.db_alias,
  File "/home/marcintustin/django/Django-1.3/django/dispatch/dispatcher.py", line 172, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/home/marcintustin/django/Django-1.3/django/contrib/auth/management/__init__.py", line 30, in create_permissions
    ctype = ContentType.objects.get_for_model(klass)
  File "/home/marcintustin/django/Django-1.3/django/contrib/contenttypes/models.py", line 38, in get_for_model
    defaults = {'name': smart_unicode(opts.verbose_name_raw)},
  File "/home/marcintustin/django/Django-1.3/django/db/models/manager.py", line 135, in get_or_create
    return self.get_query_set().get_or_create(**kwargs)
  File "/home/marcintustin/django/Django-1.3/django/db/models/query.py", line 385, in get_or_create
    obj.save(force_insert=True, using=self.db)
  File "/home/marcintustin/django/Django-1.3/django/db/models/base.py", line 460, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "/home/marcintustin/django/Django-1.3/django/db/models/base.py", line 560, in save_base
    transaction.commit_unless_managed(using=using)
  File "/home/marcintustin/django/Django-1.3/django/db/transaction.py", line 124, in commit_unless_managed
    connection.commit_unless_managed()
  File "/home/marcintustin/django/Django-1.3/django/db/backends/__init__.py", line 183, in commit_unless_managed
    self._commit()
  File "/home/marcintustin/django/Django-1.3/django/db/backends/__init__.py", line 46, in _commit
    return self.connection.commit()
pysqlite2.dbapi2.OperationalError: cannot commit transaction - SQL statements in progress

基本上,我不知道从哪里开始解决这个问题。有什么想法吗?

I'm using unittest2 together with manage.py test, and before it even seems to run any tests, it spews a horrid database error, as below. I'm in my development environment (actually on a dreamhost server for a variety of reasons), using sqlite as my database.

Even when I copy my app out of where it is for production (and edit settings.py accordingly), I still get the same error (even though it should no longer be addressing the same database file as the dev environment).

Update: Even moving all instances of my database files to a different filename still leaves me with the same error. This leads me to believe that the test environment is somehow looking at a bogus database, or something very odd is happening.

[graffias]$ python manage.py test
Creating test database for alias 'default'...
Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_manager(settings)
  File "/home/marcintustin/django/Django-1.3/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/home/marcintustin/django/Django-1.3/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/marcintustin/django/Django-1.3/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/marcintustin/django/Django-1.3/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/home/marcintustin/django/South-0.7.3-py2.5.egg/south/management/commands/test.py", line 8, in handle
    super(Command, self).handle(*args, **kwargs)
  File "/home/marcintustin/django/Django-1.3/django/core/management/commands/test.py", line 37, in handle
    failures = test_runner.run_tests(test_labels)
  File "/home/marcintustin/django/Django-1.3/django/test/simple.py", line 359, in run_tests
    old_config = self.setup_databases()
  File "/home/marcintustin/django/Django-1.3/django/test/simple.py", line 296, in setup_databases
    test_db_name = connection.creation.create_test_db(self.verbosity, autoclobber=not self.interactive)
  File "/home/marcintustin/django/Django-1.3/django/db/backends/creation.py", line 366, in create_test_db
    load_initial_data=False)
  File "/home/marcintustin/django/Django-1.3/django/core/management/__init__.py", line 166, in call_command
    return klass.execute(*args, **defaults)
  File "/home/marcintustin/django/Django-1.3/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/home/marcintustin/django/Django-1.3/django/core/management/base.py", line 351, in handle
    return self.handle_noargs(**options)
  File "/home/marcintustin/django/South-0.7.3-py2.5.egg/south/management/commands/syncdb.py", line 99, in handle_noargs
    management.call_command('migrate', **options)
  File "/home/marcintustin/django/Django-1.3/django/core/management/__init__.py", line 166, in call_command
    return klass.execute(*args, **defaults)
  File "/home/marcintustin/django/Django-1.3/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/home/marcintustin/django/South-0.7.3-py2.5.egg/south/management/commands/migrate.py", line 105, in handle
    ignore_ghosts = ignore_ghosts,
  File "/home/marcintustin/django/South-0.7.3-py2.5.egg/south/migration/__init__.py", line 191, in migrate_app
    success = migrator.migrate_many(target, workplan, database)
  File "/home/marcintustin/django/South-0.7.3-py2.5.egg/south/migration/migrators.py", line 221, in migrate_many
    result = migrator.__class__.migrate_many(migrator, target, migrations, database)
  File "/home/marcintustin/django/South-0.7.3-py2.5.egg/south/migration/migrators.py", line 298, in migrate_many
    interactive=self.interactive)
  File "/home/marcintustin/django/South-0.7.3-py2.5.egg/south/db/generic.py", line 808, in send_pending_create_signals
    interactive=interactive)
  File "/home/marcintustin/django/South-0.7.3-py2.5.egg/south/db/generic.py", line 855, in really_send_create_signal
    db=self.db_alias,
  File "/home/marcintustin/django/Django-1.3/django/dispatch/dispatcher.py", line 172, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/home/marcintustin/django/Django-1.3/django/contrib/auth/management/__init__.py", line 30, in create_permissions
    ctype = ContentType.objects.get_for_model(klass)
  File "/home/marcintustin/django/Django-1.3/django/contrib/contenttypes/models.py", line 38, in get_for_model
    defaults = {'name': smart_unicode(opts.verbose_name_raw)},
  File "/home/marcintustin/django/Django-1.3/django/db/models/manager.py", line 135, in get_or_create
    return self.get_query_set().get_or_create(**kwargs)
  File "/home/marcintustin/django/Django-1.3/django/db/models/query.py", line 385, in get_or_create
    obj.save(force_insert=True, using=self.db)
  File "/home/marcintustin/django/Django-1.3/django/db/models/base.py", line 460, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "/home/marcintustin/django/Django-1.3/django/db/models/base.py", line 560, in save_base
    transaction.commit_unless_managed(using=using)
  File "/home/marcintustin/django/Django-1.3/django/db/transaction.py", line 124, in commit_unless_managed
    connection.commit_unless_managed()
  File "/home/marcintustin/django/Django-1.3/django/db/backends/__init__.py", line 183, in commit_unless_managed
    self._commit()
  File "/home/marcintustin/django/Django-1.3/django/db/backends/__init__.py", line 46, in _commit
    return self.connection.commit()
pysqlite2.dbapi2.OperationalError: cannot commit transaction - SQL statements in progress

Basically, I have no idea where to start with fixing this. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文