Django mysql数据库不接受日期格式 [英] Django mysql database not accepting date format

查看:83
本文介绍了Django mysql数据库不接受日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我要发送到服务器的json对象(Http帖子)

This is the json object I'm sending to the server (Http post)


{ user_id: 91 ** *******, user_name: ********,生日: 1994-26-01,位置:印度新德里}

{"user_id":"91*********","user_name":"********","birthday":"1994-26-01","location":"New Del India"}

我在客户端收到内部服务器错误。检查服务器时,它说:

I get an internal server error at the client. On checking the server it says:


HTTP 400错误请求内容类型:application / json变化:接受
允许:GET ,POST,HEAD,OPTIONS

HTTP 400 BAD REQUEST Content-Type: application/json Vary: Accept Allow: GET, POST, HEAD, OPTIONS

{
birthday:[
日期格式错误。请改用以下格式之一:YYYY [ -MM [-DD]]
]}

{ "birthday": [ "Date has wrong format. Use one of these formats instead: YYYY[-MM[-DD]]" ] }

但是当数据库存储日期时,它将日期保存在我使用相同的格式,那我哪里出错了?并以什么格式发送日期字段中的值?

But when the db stores the dates, it saves it in the same format I do, then where am I going wrong? And in what format should I send the value in the date field ?

注意:我是django的菜鸟

Note: I'm a noob at django

推荐答案

该消息说,您需要以YYYY-MM-DD格式(日期为4位数字,月份为2位,日期为2位)传递日期。相反,从您的示例中我们可以看到,您使用的是passong 1994-26-01,即YYYY-DD-MM(因为26只能是一天)。因此,您会收到错误消息。

The message says that you need to pass the date in the YYYY-MM-DD format (4 digits for year, 2 for month, 2 for day). Instead, as we can see from your example you are passong "1994-26-01" which is YYYY-DD-MM (since 26 can only be day). That's why you are receiving the error.

您需要修正传递的日期时间格式,YYYY-DD-MM在任何情况下均无效。

You need to fix the datetime format you pass, YYYY-DD-MM is not valid in any case.

这篇关于Django mysql数据库不接受日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆