field with null=True not accepting nulls in Django [closed]
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!
精彩评论