首页 > 解决方案 > “list_name”列中的空值违反非空约束细节:

问题描述

在此处输入图像描述我创建了一个函数 makeList 来将项目插入列表中。每当我尝试通过邮递员检查 API 是否有 POST 请求时,都会收到以下错误 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')

型号列表类别

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

    def __str__(self):
        return self.list_name

上面给出的邮递员截图

标签: djangodjango-modelsdjango-viewspostman

解决方案


推荐阅读