django:带反向外键的型号?

django:带反向外键的型号?,django,foreign-keys,models,Django,Foreign Keys,Models,我这里有鸡和蛋的问题。首先,我有一个userprofile类,它建立在django的默认用户模型之上 class UserProfile(models.Model): def __unicode__(self): return self.user.username user = models.OneToOneField(User, unique=True) exam = models.ForeignKey('questions.Exam', null=Tr

我这里有鸡和蛋的问题。首先,我有一个userprofile类,它建立在django的默认用户模型之上

class UserProfile(models.Model):
    def __unicode__(self):
        return self.user.username
    user = models.OneToOneField(User, unique=True)
    exam = models.ForeignKey('questions.Exam', null=True)
接下来,我有一节考试课

class Exam(models.Model):
    def __unicode__(self):
        return self.id
    user = models.ForeignKey(UserProfile)
用户配置文件和考试模型在不同的应用程序中。然而,他们彼此都有外国钥匙。我知道它的设计很糟糕,但这是我的特殊要求。但是,要检查的UserProfile foreignkey可以为Null。但每当我尝试在Admin中创建考试时,我都会收到一个错误,即“UserProfile”是必填字段。当我尝试创建用户时,情况正好相反。有没有办法打破僵局?或者我应该重新设计我的应用程序

我应该重新设计我的应用程序吗


几乎可以肯定。但是,这个实际问题是由以下事实引起的:您有
null=True
,它正确地设置了数据库,允许外键字段上的
null
s,但您没有添加
blank=True
,Django使用它来验证正确的条目。再加上这一点,这一部分至少应该能起作用。

它起作用了。但我会改变我的设计,让它更流线型。谢谢