How do I get syncdb db_table and app_label to play nicely together

Posted by Chris Heisel on Stack Overflow See other posts from Stack Overflow or by Chris Heisel
Published on 2010-09-23T01:13:48Z Indexed on 2011/01/13 15:53 UTC
Read the original article Hit count: 442

Filed under:
|

I've got a model that looks something like this:

class HeiselFoo(models.Model):
    title = models.CharField(max_length=250)

    class Meta:
        """ Meta """
        app_label = "Foos"
        db_table = u"medley_heiselfoo_heiselfoo"

And whenever I run my test suite, I get an error because Django isn't creating the tables for that model.

It appears to be an interaction between app_label and db_table -- as the test suite runs normally if db_table is set, but app_label isn't.

Here's a link to the full source code: http://github.com/cmheisel/heiselfoo

Here's the traceback from the test suite:

E
======================================================================
ERROR: test_truth (heiselfoo.tests.HeiselFooTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/chris/Code/heiselfoo/ve/lib/python2.6/site-packages/heiselfoo/tests.py", line 10, in test_truth
    f.save()
  File "/Users/chris/Code/heiselfoo/ve/lib/python2.6/site-packages/django/db/models/base.py", line 434, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "/Users/chris/Code/heiselfoo/ve/lib/python2.6/site-packages/django/db/models/base.py", line 527, in save_base
    result = manager._insert(values, return_id=update_pk, using=using)
  File "/Users/chris/Code/heiselfoo/ve/lib/python2.6/site-packages/django/db/models/manager.py", line 195, in _insert
    return insert_query(self.model, values, **kwargs)
  File "/Users/chris/Code/heiselfoo/ve/lib/python2.6/site-packages/django/db/models/query.py", line 1479, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/Users/chris/Code/heiselfoo/ve/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 783, in execute_sql
    cursor = super(SQLInsertCompiler, self).execute_sql(None)
  File "/Users/chris/Code/heiselfoo/ve/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 727, in execute_sql
    cursor.execute(sql, params)
  File "/Users/chris/Code/heiselfoo/ve/lib/python2.6/site-packages/django/db/backends/sqlite3/base.py", line 200, in execute
    return Database.Cursor.execute(self, query, params)
DatabaseError: no such table: medley_heiselfoo_heiselfoo

----------------------------------------------------------------------
Ran 1 test in 0.004s

FAILED (errors=1)
Creating test database 'default'...
No fixtures found.
medley_heiselfoo_heiselfoo
Destroying test database 'default'...

© Stack Overflow or respective owner

Related posts about django

Related posts about django-models