【发布时间】:2012-07-07 11:04:38
【问题描述】:
这是我的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
我错过了什么?
【问题讨论】:
标签: python django referential-integrity integrity database-integrity