django:sqlite3.OperationalError:没有这样的表

时间:2021-05-01 15:27:02

i don't now why, but from one day to another y started to have problems when i tried to run the tests. I'm using django 1.1 (customer requirements) and when i running test whith:

我现在不知道为什么,但是当我试图运行测试时,从一天到另一天我开始遇到问题。我正在使用django 1.1(客户要求),当我运行测试时:

python manage.py test --setting=settingsTest

it throw:

抛出:

Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_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

but i have in settingsTest.py

但我在settingsTest.py

INSTALLED_APPS = (
    'django.contrib.auth',
    ...

    'site.programas_act',
    ...
)

and in /var/www/site/programas_act/models.py

在/var/www/site/programas_act/models.py中

class ActividadesPrograma(models.Model):
    ...

I removed the file named in settingsTest.DATABASE_NAME and run:

我删除了settingsTest.DATABASE_NAME中指定的文件并运行:

python manage.py syncdb --setting=settingsTest

but still failing.

但仍然失败。

If i run in django shell_plus:

如果我在django shell_plus中运行:

import settings
print settings.INSTALLED_APPS
for app in settings.INSTALLED_APPS:
    print app

I can see the app, but when i run:

我可以看到该应用程序,但当我运行时:

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

I can't found that tablename.

我找不到tablename。

Anyone can help me?

有人可以帮帮我吗?

Thanks

谢谢

3 个解决方案

#1


6  

I had this problem, too. Turned out that I had to add a TEST_NAME property in the settings.py file to identify the test database properly. It solved the problem for me:

我也有这个问题。原来我必须在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'),
        }
    }

#2


4  

Are these Selenium tests, by any chance? This page says you need to define a TEST_NAME for your database, because for some reason the in-memory database is quite broken.

这些Selenium是否有机会进行测试?此页面表示您需要为数据库定义TEST_NAME,因为由于某种原因,内存数据库已经完全损坏。

#3


0  

I think 'manage.py test' starts with empty database, so there's no way how 'syncdb' can help you.

我认为'manage.py test'从空数据库开始,所以'syncdb'无法帮助你。

Also I'm not sure if it's typo just in your question, but settings parameter is called

此外,我不确定它是否只是在您的问题中,但调用设置参数

--settings

and not:

并不是:

--setting

btw. if you're importings settings in code, use import this way:

顺便说一句。如果您是代码中的导入设置,请使用以下方式导入:

from django.conf import settings

#1


6  

I had this problem, too. Turned out that I had to add a TEST_NAME property in the settings.py file to identify the test database properly. It solved the problem for me:

我也有这个问题。原来我必须在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'),
        }
    }

#2


4  

Are these Selenium tests, by any chance? This page says you need to define a TEST_NAME for your database, because for some reason the in-memory database is quite broken.

这些Selenium是否有机会进行测试?此页面表示您需要为数据库定义TEST_NAME,因为由于某种原因,内存数据库已经完全损坏。

#3


0  

I think 'manage.py test' starts with empty database, so there's no way how 'syncdb' can help you.

我认为'manage.py test'从空数据库开始,所以'syncdb'无法帮助你。

Also I'm not sure if it's typo just in your question, but settings parameter is called

此外,我不确定它是否只是在您的问题中,但调用设置参数

--settings

and not:

并不是:

--setting

btw. if you're importings settings in code, use import this way:

顺便说一句。如果您是代码中的导入设置,请使用以下方式导入:

from django.conf import settings