manage.py syncdb doesn't add tables for some models

twneale picture twneale · Sep 16, 2009 · Viewed 8.4k times · Source

My second not-so-adept question of the day: I have a django project with four installed apps. When I run manage.py syndb, it only creates tables for two of them. To my knowledge, there are no problems in any of my models files, and all the apps are specified in INSTALLED_APPS in my settings file. Manage.py syndb just seems to ignore two of my apps.

One thing that is unique about the two "ignored" apps is that the models files import models from the other two apps and use them as foreign keys (don't know if this is good/bad practice, but helps me stay organized). I don't think that's the problem though, because I commented out the foreign key-having models and the tables still weren't created. I'm stumped.

UPDATE: When I comment out the lines importing models files from other apps, syndb creates my tables. Perhaps I'm not understanding something about how models files in separate apps relate to other other. I though it was ok to use a model from another app as a foreign key by simply importing it. Not true?

Answer

monkut picture monkut · Sep 17, 2009

I think I ran across something similar.

I had an issue where a model wasn't being reset. In this case it turned out that there was an error in my models that wasn't being spit out.

Although I think syncdb, when run, spit out some kind of error.

In any case try to import your models file from the shell and see if you can.

$ manage.py shell
>>> from myapp import models
>>>

If theres an error in the file this should point it out.

According to your update, it sounds like you may have a cross-import issue. Instead of:

from app1.models import X

class ModelA(models.Model):
    fk = models.ForeignKey(X)

Try:

class ModelA(models.Model):
    fk = models.ForeignKey("app1.X")

... although I think you should get an error on syncdb.