我正在写一些模特。具体来说,是一个UserProfile模型,它由User上的post保存挂钩创建。
这里发生了一些奇怪的事情。测试套件在一台计算机上传递,在另一台计算机上失败。错误消息是:profile_userprofile.organization_id may not be NULL
,但这是我的模型:
class UserProfile(models.Model):
'Profile object for a user'
user = models.ForeignKey(User, unique=True)
organization = models.ForeignKey(
'organization.Organization',
related_name='volunteers',
null=True,
)
显然,组织应该允许空值,但事实并非如此。关于这里出了什么问题的任何想法?从shell调用User.objects.create()
时会发生同样的事情。
(哦,这是钩子)
@receiver(models.signals.post_save, sender=User)
def user_post_save(sender, instance, **kwargs):
'create a userprofile object for a user if one does not exist'
UserProfile.objects.get_or_create(user=instance)
答案 0 :(得分:0)
听起来第二台机器上的数据库没有同步。删除它并重新运行syncdb
。
答案 1 :(得分:0)
也许您正在寻找的是blank=True
。
答案 2 :(得分:0)
我错过了一次迁移!糟糕!