在Django中验证模型时出现未处理的异常

时间:2014-09-15 09:51:26

标签: python django django-models

我在编写正在编写的Django Web应用程序的代码时遇到错误

在控制台中,它显示:

Validating models...
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x028A2BB8>

控制台中的错误跟踪直到我的程序中的错误位置

File "C:\Uni Work\R&D\yellowProject\teamList\models.py", line 9, in <module>
class UserTeamEntry(models.Model):
File "C:\Python34\lib\site-packages\django\db\models\base.py", line 144, in __new__
new_class.add_to_class(obj_name, obj)
File "C:\Python34\lib\site-packages\django\db\models\base.py", line 264, in add_to_class
value.contribute_to_class(cls, name)
TypeError: contribute_to_class() missing 1 required positional argument: 'name'

我的models.py:

from django.db import models
from django.contrib.auth.models import User

class UserTeamEntry(models.Model):

    user = models.OneToOneField(User)
    position_choices = (('TEAMMEMBER', 'Team Member'),
                        ('MANAGER', 'Manager'),)
    userID = models.AutoField(primary_key = True)
    userPosition = models.CharField(max_length = 10, choices = position_choices)
    userShare = models.BooleanField

1 个答案:

答案 0 :(得分:7)

您忘记在BooleanField之后添加括号()。所以,添加它们:

userShare = models.BooleanField()