那是我的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()
添加用户工作得很好:
>>> user = User.objects.create("john_doe@planetearth.com")
尝试添加链接时出现完整性错误:
>>> link = Link.objects.create("stackoverflow.com")
IntegrityError: shortener_link.short_end may not be NULL
我错过了什么?