Manage.py syncdb does not add tables for some models

My second not-so-adept question of the day: I have a django project with four applications installed. When I run manage.py syndb, it creates tables for only two of them. As far as I know, in any of my model files there are no problems, and all applications are listed in INSTALLED_APPS in my settings file. Synthesis of Manage.py just ignores my two applications.

One thing that is unique about the two “ignored” applications is that file models import models from two other applications and use them as foreign keys (I don't know if this is good / bad practice, but it helps me stay organized). I don't think the problem is, though, because I commented on the models with the foreign key, and the tables have not yet been created. I'm at a dead end.

UPDATE: when I comment on lines importing model files from other applications, syndb creates my tables. Perhaps I do not understand how model files in individual applications relate to others. I, although it was normal to use the model from another application as a foreign key, simply importing it. Not true?

+4
source share
2 answers

Unfortunately, manage.py cannot load the application where there is an import error in its models.py ( ticket # 10706 ). Most likely, there is a typo in one of your models.py files ... carefully check all import instructions (or use pylint).

Syncdb recently stopped loading several of my applications, and sqlall gave me the error "Application with label foo could not be found." Unaware that this sometimes means that “an application with the label foo was found, but could not be loaded because ImportError was called,” it took me half an hour to realize that I was trying to import “haslib” instead of “hashlib "in one of my models.py files.

+6
source

I think I ran into something similar.

I had a problem when the model was not reset. In this case, it turned out that there was an error in my models that did not spit out.

Although I think that syncdb at startup spits out some kind of error.

In any case, try importing the model file from the shell and see if you can.

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

If there is an error in the file, this should indicate this.

According to your update, it looks like you might have a cross import problem. Instead:

 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 message on syncdb.

+8
source

All Articles