Django syncdb没有为我的应用程序制作表格 [英] Django syncdb not making tables for my app
问题描述
它以前工作,现在没有。 python manage.py syncdb
不再为我的应用程序制作表。
从 settings.py :
INSTALLED_APPS =(
'django.contrib.auth',
'django.contrib .contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'mysite.myapp',
'django.contrib.admin'
)
我可以做错什么?在 models.py 中编辑此模型时,这个突破似乎是一致的,但这可能是完全巧合的。我评论了我改变的行,但仍然不起作用。
class MyUser(models.Model):
user = models.ForeignKey(User,unique = True)
takeReqSets = models.ManyToManyField(RequirementSet,blank = True)
takingTerms = models.ManyToManyField(Term,blank = True)
takeCourses = models.ManyToManyField(Course,through = TakingCourse,blank = True)
school = models.ForeignKey(School)
#minCreditsPerTerm = models.IntegerField(blank = True)
#maxCreditsPerTerm = model.IntegerField(blank = True)
#optimalCreditsPerTerm = models.IntegerField(blank = True)
更新:
当我运行 python manage.py loadddata initial_data
给出错误:
DeserializationError:无效的模型标识符:myapp.SomeModel
加载此数据之前工作正常。这个错误被抛出在数据文件中的第一个数据对象上。
SOLVED:
通过删除此行来修复:
/ pre>
解决方案我敢打赌,上面提到的SomeModel模型(不一定是MyUser)有一个问题,意味着它不能由loaddata导入。如果不是SomeModel,那么在同一个models.py中定义SomeModel的模型。
您是否尝试过
./ manage.py validate
?即使说所有的模型都很好,有时候如果应用程序的models.py有一个错误,整个应用程序对于manage.py会变得不可见。我不能说我知道为什么这是这种情况,但似乎响了一声。It used to work, and now it doesn't.
python manage.py syncdb
no longer makes tables for my app.From settings.py:
INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'mysite.myapp', 'django.contrib.admin', )
What could I be doing wrong? The break appeared to coincide with editing this model in models.py, but that could be total coincidence. I commented out the lines I changed, and it still doesn't work.
class MyUser(models.Model): user = models.ForeignKey(User, unique=True) takingReqSets = models.ManyToManyField(RequirementSet, blank=True) takingTerms = models.ManyToManyField(Term, blank=True) takingCourses = models.ManyToManyField(Course, through=TakingCourse, blank=True) school = models.ForeignKey(School) # minCreditsPerTerm = models.IntegerField(blank=True) # maxCreditsPerTerm = models.IntegerField(blank=True) # optimalCreditsPerTerm = models.IntegerField(blank=True)
UPDATE:
When I run
python manage.py loadddata initial_data
, it gives an error:DeserializationError: Invalid model identifier: myapp.SomeModel
Loading this data had worked fine before. This error is thrown on the very first data object in the data file.
SOLVED:
Fixed by removing this line:
from stringprep import bl
解决方案I'd bet that the SomeModel model you mention above (not necessarily MyUser) has got a problem with it which means it can't be imported by loaddata. If not SomeModel, then a model in the same models.py that SomeModel is defined in.
Have you tried
./manage.py validate
? Even if that says all models are fine, sometimes if there's an error in a models.py of an an app, the entire app becomes 'invisible' to manage.py. I can't say I know why this is the case, but seems to ring a bell.这篇关于Django syncdb没有为我的应用程序制作表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!