Database test error

13 views
Skip to first unread message

xina towner

unread,
Feb 13, 2012, 4:09:02 AM2/13/12
to django...@googlegroups.com
Hello, I still get this error:

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_manager(settings)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/south/management/commands/test.py", line 8, in handle
    super(Command, self).handle(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py", line 37, in handle
    failures = test_runner.run_tests(test_labels)
  File "/usr/local/lib/python2.7/dist-packages/django/test/simple.py", line 358, in run_tests
    suite = self.build_suite(test_labels, extra_tests)
  File "/usr/local/lib/python2.7/dist-packages/django/test/simple.py", line 248, in build_suite
    suite.addTest(build_suite(app))
  File "/usr/local/lib/python2.7/dist-packages/django/test/simple.py", line 77, in build_suite
    test_module = get_tests(app_module)
  File "/usr/local/lib/python2.7/dist-packages/django/test/simple.py", line 35, in get_tests
    test_module = __import__('.'.join(app_path + [TEST_MODULE]), {}, {}, TEST_MODULE)
  File "/home/xino/workspace/unnamedapp/quests/tests.py", line 9, in <module>
    from views_web import *
  File "/home/xino/workspace/unnamedapp/quests/views_web.py", line 6, in <module>
    from quests import views_generic
  File "/home/xino/workspace/unnamedapp/quests/views_generic.py", line 3, in <module>
    from quests.forms import *
  File "/home/xino/workspace/unnamedapp/quests/forms.py", line 487, in <module>
    class SearchQuestForm(forms.Form):
  File "/home/xino/workspace/unnamedapp/quests/forms.py", line 494, in SearchQuestForm
    [CATEGORY_CHOICES.append((c.id, c.name)) for c in Category.objects.all()]    
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 107, in _result_iter
    self._fill_cache()
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 772, in _fill_cache
    self._result_cache.append(self._iter.next())
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 273, in iterator
    for row in compiler.results_iter():
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 680, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 735, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", line 234, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.DatabaseError: no such table: quests_category

The problem es the order that django creates the tables in the database. Can I change this?

--
Gràcies,

Rubén

akaariai

unread,
Feb 14, 2012, 8:11:35 AM2/14/12
to Django users
On Feb 13, 11:09 am, xina towner <xinatow...@gmail.com> wrote:
> Hello, I still get this error:
<SNIP>
> The problem es the order that django creates the tables in the database.
> Can I change this?

Are you sure the problem is not that importing the tests will generate
a query? The offending place seems to be:

> from quests.forms import *
> File "/home/xino/workspace/unnamedapp/quests/forms.py", line 487, in
> <module>
> class SearchQuestForm(forms.Form):
> File "/home/xino/workspace/unnamedapp/quests/forms.py", line 494, in
> SearchQuestForm
> [CATEGORY_CHOICES.append((c.id, c.name)) for c in
> Category.objects.all()]

I am pretty sure that what is happening is that the tests are imported
before the database is created. And because of that, the table doesn't
exist at that point. It is only created after the import of the tests.

If the above hypothesis is correct, the solution would be to make the
Category.objects.all() query above lazy, so that it is executed only
when first needed, not at import time.

- Anssi
Reply all
Reply to author
Forward
0 new messages