django - “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
上面给出的邮递员截图
解决方案
推荐阅读
- r - 按组添加颜色
- wordpress - Wordpress 主页在更改 FTP 服务器后重定向了您太多时间错误
- haskell - 什么是 haskell 中的自然转换?
- android - android 与 kotlin 协程,如果 CoroutineExceptionHandler 附加在 IDE 中,则单元测试失败不会显示
- android - FCM 云消息不再注册新主题
- php - 为什么不显示类别?
- java - 尝试从由 UID 和 push() 方法生成的两个唯一键下并使用查询从 Firebase 获取数据
- python - spaCy:如何为此使用一些加载的模型将命名实体写入现有的 Doc 对象?
- postgresql - 如何在 Postgres 中创建第一个数据库
- sqlalchemy - 基于父对象创建子对象