Django模型syncdb中整数字段错误
我正在用Python的Django框架开发一个应用,但我对它还不太熟悉,所以我的问题可能听起来很简单。当我尝试运行syncdb的时候,遇到了一个错误。
TypeError: Error when calling the metaclass bases
unbound method contribute_to_class() must be called with IntegerField
instance as first argument (got ModelBase instance instead)
这是我在models.py文件中的一段代码。
class Type(models.Model):
name = models.CharField(max_length=60)
description = models.CharField(max_length = 200)
class TypeModel(models.Model):
importance = models.IntegerField
name = models.CharField(max_length=70)
description = models.CharField(max_length=200)
type = models.ForeignKey(Type)
当我尝试运行下面这个命令时,
python manage.py syncdb
我就会看到问题开头提到的那个错误。我还想说,在我把TypeModel添加到models.py文件之前,一切都运行得很好。请问我哪里出了问题?如果有人能帮我,我会非常感激。
2 个回答
1
你缺少了函数的括号。这样做:
importance = models.IntegerField()
而不是:
importance = models.IntegerField
2
你的 importance = models.IntegerField
,可以用 models.IntegerField(default=0)
或者 models.IntegerField()
来替代,这样更好。