字段将模型的关系定义为抽象或未安装

时间:2015-08-17 15:11:01

标签: python django foreign-keys abstract

当我尝试同步数据库或运行程序时,我尝试设置外部并继续收到此错误。

class OffenseStats(models.Model):
    passingYards = models.IntegerField()
    passingTouchdowns = models.IntegerField()
    rushingTouchdowns = models.IntegerField()
    receivingTouchdowns = models.IntegerField()
    receivingYards = models.IntegerField()
    rushingYards = models.IntegerField()
    yardsAfterCatch = models.IntegerField()
    catches = models.IntegerField()
    pancakes = models.IntegerField()
    sacksAllowed = models.IntegerField()
    puntReturnedTouchdowns = models.IntegerField()
    kickReturnedTouchdowns = models.IntegerField()
    def __str__(self):
        return 'ID: %s', self.statID


class StudentAccount(PersonAccount):

    highSchool = models.CharField(max_length=Account.MAX_SIZE)
    position = models.CharField(max_length=Account.MAX_SIZE)
    year = models.IntegerField(default=3)
    status = models.CharField(max_length=Account.MAX_SIZE)
    article = models.ManyToManyField(studentArticle)
    stats = models.ManyToManyField(studentStats)
    video = models.ManyToManyField(studentVideo)
    references = models.ManyToManyField(studentReferences)
    recruitingBoard = models.ManyToManyField(studentRecuritingBoard)
    studentMessage = models.ManyToManyField(Messages)
    offenseStat = models.ForeignKey('OffenseStats')

我之前看到的所有问题都是通过正确拼写或导入模型来修复的。两个模型都在同一个文件中。不确定我是否只是没有足够的把握

1 个答案:

答案 0 :(得分:0)

this你的问题是关于攻击性统计数据的单引号。您需要来自OffenseStats的主键,而不是字符串“OffenseStats”

您的最后一行代码应如下所示:         crimeStat = models.ForeignKey(OffenseStats)