Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django: sqlite3.OperationalError: no such table

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:

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

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

    'site.programas_act',
    ...
)

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

class ActividadesPrograma(models.Model):
    ...

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

python manage.py syncdb --setting=settingsTest

but still failing.

If i run in 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.

Anyone can help me?

Thanks

like image 583
gsoriano Avatar asked Dec 07 '11 14:12

gsoriano


1 Answers

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:

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'),
        }
    }
like image 182
pkout Avatar answered Oct 26 '22 05:10

pkout