我正在尝试使用python manage.py test
运行测试套件,但我遇到了一个错误,结果如下:
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: type "hstore" does not exist
LINE 1: ..., "options" varchar(255)[] NOT NULL, "conditions" hstore NOT...
此时我想进入调试器以查看完整的sql
语句。为此,我运行pip install django-pdb
并将以下行添加到settings.py
(根据instructions):
# Order is important and depends on your Django version.
# With Django 1.7+ put it towards the beginning, otherwise towards the end.
INSTALLED_APPS = (
...
'django_pdb',
...
)
# Make sure to add PdbMiddleware after all other middleware.
# PdbMiddleware only activates when settings.DEBUG is True.
MIDDLEWARE_CLASSES = (
...
'django_pdb.middleware.PdbMiddleware',
)
然后我尝试使用--pm
选项重新运行测试:
python manage.py test lucy_web.tests.notifications --pm
然而,这是不被承认的:
manage.py test: error: unrecognized arguments: --pm
我还尝试使用--ipdb
而不是--pm
运行此命令,但它似乎不起作用:我只是收到一条错误消息而不会进入调试器。任何想法可能是什么问题? test
命令可能不支持事后调试吗?
答案 0 :(得分:1)
Django Running Test您需要启用hstore扩展程序。还运行命令
选项应在test
命令之后,即。
python manage.py test --pm lucy_web.tests.notifications
from django.contrib.postgres.operations import HStoreExtension
class Migration(migrations.Migration):
...
operations = [
HStoreExtension(),
...
]