问题描述
我正在使用python djnago开发应用程序,因此它是新手,所以我的问题听起来很原始,尝试运行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文件之前,它曾经可以完美地工作,我在哪里犯错,如果有人可以提供帮助,我将非常感谢
1楼
您的importance = models.IntegerField
,好models.IntegerField(default=0)
或models.IntegerField()
2楼
您缺少该函数的括号。 做这个:
importance = models.IntegerField()
代替:
importance = models.IntegerField