The DATE type is used for values with a date part but no time part.
MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format.
The supported range is '1000-01-01' to '9999-12-31'.
The DATETIME type is used for values that contain both date and time
parts. MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD
HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to
'9999-12-31 23:59:59'.
The TIMESTAMP data type is used for values that contain both date
and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC
to '2038-01-19 03:14:07' UTC.
MySQL确实有“零日期”:
Invalid DATE, DATETIME, or TIMESTAMP values are converted to the
"zero" value of the appropriate type ('0000-00-00' or '0000-00-00
00:00:00').
问题是你的默认值没有意义。没有零日,也没有零月。Python可以表示为
datetime
对象的最小日期是:所以1月1日。在某些(大多数)数据库中,范围更为严格。例如在MySQL中,范围是:
MySQL确实有“零日期”:
但是没有好的方法将其包装到
datetime
对象,因为正如前面所说,它超出了可表示的范围。在您可以使用建议的here解决方案,它基本上构造了一个新的Django}映射到这个零值上。但据我所知,您可以不使用标准的
ZeroDateTimeField
,将{DateTimeField
来实现这一点。在因此,您可以使用数据库可表示的最小可表示
datetime
对象,也可以使用NULL
。在相关问题 更多 >
编程相关推荐