开发者

field with null=True not accepting nulls in Django [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

I'm writing some models. Specifically, a UserProfile model which is created by a post save hook on User.

Some strange things are happening here. The test suite passes on one computer, and fails on another. The error message is : profile_userprofile.organization_id may not be NULL, and yet here is my model:

class UserProfile(models.Model):
    'Profile obj开发者_开发知识库ect for a user'
    user = models.ForeignKey(User, unique=True)
    organization = models.ForeignKey(
        'organization.Organization',
        related_name='volunteers',
        null=True,
    )

obviously, organization should allow null values, but it doesn't. Any ideas as to what's going wrong here? The same thing happens when calling User.objects.create() from the shell.

(oh, here's the hook)

@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)


Sounds like the database is not on sync in the second machine. Drop it and re-run syncdb.


Perhaps what you are looking for is blank=True.


I was missing a migration! Whoops!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜