我正在尝试使用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
命令可能不支持事后调试吗?
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(),
...
]