“ list_name”列中的空值违反了非空约束DETAIL:

时间:2019-06-11 08:07:20

标签: django django-models django-views postman

enter image description here我创建了一个函数makeList来将项目插入列表。每当我尝试通过邮递员检查POST请求的API时,都会收到以下错误消息 null value in column "list_name" violates not-null constraint DETAIL: Failing row contains (16, null).

查看功能

    if request.method == 'POST':
        list_item = request.POST.get('list_item')
        ListCategory.objects.create(list_name=list_item)

        # return something not yet decided
    full_list = ListCategory.objects.order_by('id')

    full_list = serializers.serialize('json',full_list)
    return HttpResponse(full_list, content_type='application/json')

模型ListCategory

class ListCategory(models.Model):
    # user_id = models.IntegerField()
    list_name = models.CharField(max_length=200)

    def __str__(self):
        return self.list_name

邮递员上面的屏幕截图

0 个答案:

没有答案