(django.db.utils.IntegrityError:唯一约束失败:items_purchase.item_id)
这是我尝试迁移名为“ items”的应用程序时遇到的错误。
app name = items
model name = Purchase
我不明白什么是item_id
。
class Purchase(models.Model):
name=models.CharField(max_length=200)
phone=models.IntegerField(default=0)
email=models.EmailField()
address=models.CharField(max_length=200)
pin=models.IntegerField(default='0')
state=models.CharField(max_length=200)
class Item(models.Model):
name=models.CharField(max_length=200)
c=models.ForeignKey(Category, on_delete=models.CASCADE)
photo=models.ImageField(default='0')
def __str__(self):
return 'Item: {}'.format(self.name)
def confirm(request):
f=PurchaseForm(request.POST)
if f.is_valid():
name = f.cleaned_data['name']
phone = f.cleaned_data['phone']
email = f.cleaned_data['email']
address = f.cleaned_data['address']
pin = f.cleaned_data['pin']
state = f.cleaned_data['state']
f.save()
template=loader.get_template('items/confirm.html')
context={'f':f}
return HttpResponse(template.render(context,request))