python - django integrity error, many to many relationship -
that's models.py:
class user(models.model): email = models.emailfield() def __unicode__(self): return str(self.email) class link(models.model): link = models.urlfield() users = models.manytomanyfield(user, through='shorturl') class shorturl(models.model): link = models.foreignkey(link) user = models.foreignkey(user) short_end = models.charfield(max_length=20) counter = models.integerfield()
adding users works fine:
>>> user = user.objects.create("john_doe@planetearth.com")
i integrity error when try add link:
>>> link = link.objects.create("stackoverflow.com") integrityerror: shortener_link.short_end may not null
what missing?
you need create link this:
link.objects.create(link="stackoverflow.com", user = request.user, short_end = 'stack', counter = 0)
since of fields required.
Comments
Post a Comment