我正在尝试将 HTSQL 用于我的 Django 项目之一。为此,我遵循了给出的程序HERE http://htsql.org/blog/2012/introducing-django-gateway.html用于提供 HTSQL/Django 要求。然后我克隆了 HTSQL 存储库以尝试其中的示例/演示HERE https://bitbucket.org/prometheus/htsql/src/e236a434ad3b/demo/django。演示示例中使用的默认数据库是 sqlite3。
我已经在 Django v 1.4 和 Django v 1.3.1 上尝试过这个演示(必须在 Django v 1.3.1 的 settings.py 中进行一些调整)。按照指示HTSQL Django-gateway 博客 http://htsql.org/blog/2012/introducing-django-gateway.html,我在django项目shell中编写了以下代码:
>>> from htsql_django import produce
>>> query = "/polls_poll{question, total:=sum(polls_choice.votes)}"
>>> for row in produce(query):
>>> print "%s: %s" % (row.question, row.total)
它抛出以下错误:
TransactionManagementError: This code isn't under transaction management
整个错误跟踪可以在以下位置查看pastebin http://pastebin.ca/2197235
我也在我自己的新项目上尝试过这个,但同样的错误。
当您从 Django shell 使用 HTSQL 时,您必须显式打开一个事务:
>>> from django.db import transaction
>>> from htsql_django import produce
>>> with transaction.commit_on_success():
... query = "/polls_poll{question, total:=sum(polls_choice.votes)}"
... for row in produce(query):
... print "%s: %s" % (row.question, row.total)
很抱歉,文档对此并不清楚。我们可能会在未来的版本中更改它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)