views:

21

answers:

2

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'...
A: 

Caveat: this is not a direct answer to your question.

From looking at your code in github I find that you have defined the model inside models.py. And yet you have defined app_label inside your model's Meta. Is there a reason for doing this?

Django's documentation says that app_label is meant to be used

If a model exists outside of the standard models.py (for instance, if the app’s models are in submodules of myapp.models), the model must define which app it is part of:

Given that, I don't see any reason to define an app_label in your case. Hence my question. Perhaps you are better off without defining the app_label after all.

Manoj Govindan
Manoj, thanks. The reason I'm defining an app_label is because for purposes of the admin, I want the model to appear under a different label than "heiselfoo" because I'm extending and overriding some models in a 3rd party app, and I want my models to appear under that app_label.
Chris Heisel
A: 

Ok, I'm a moron. You need to have an app in INSTALLED_APPS that matches your app_label or your tables won't get created.

Chris Heisel