我现在不知道为什么,但是当我试图进行测试时,从一天到另一天我开始遇到问题.我正在使用django 1.1(客户要求),当我运行测试时:
python manage.py test --setting=settingsTest
抛出:
Traceback (most recent call last): File "manage.py", line 11, inexecute_manager(settings) File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py", line 362, in execute_manager ... File "/usr/lib/pymodules/python2.6/django/db/backends/sqlite3/base.py", line 193, in execute return Database.Cursor.execute(self, query, params) sqlite3.OperationalError: no such table: programas_act_actividadesprograma
但我有settingsTest.py
INSTALLED_APPS = ( 'django.contrib.auth', ... 'site.programas_act', ... )
在/var/www/site/programas_act/models.py中
class ActividadesPrograma(models.Model): ...
我删除了settingsTest.DATABASE_NAME中指定的文件并运行:
python manage.py syncdb --setting=settingsTest
但仍然失败.
如果我在django shell_plus中运行:
import settings print settings.INSTALLED_APPS for app in settings.INSTALLED_APPS: print app
我可以看到该应用程序,但是当我运行时:
from django.db import connection cursor = connection.cursor() qry="""SELECT name FROM sqlite_master WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%%' UNION ALL SELECT name FROM sqlite_temp_master WHERE type IN ('table','view') ORDER BY 1""" cursor.execute(qry) results = cursor.fetchall() for tablename in results: print tablename
我找不到tablename.
有人可以帮帮我吗?
谢谢
我也有这个问题.原来我必须在settings.py文件中添加TEST_NAME属性才能正确识别测试数据库.它解决了我的问题:
if 'test' in sys.argv: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(os.path.dirname(__file__), 'test.db'), 'TEST_NAME': os.path.join(os.path.dirname(__file__), 'test.db'), } }