Is it possible to save datetime to DynamoDB?(是否可以将日期时间保存到 DynamoDB?)
问题描述
我有下一个代码:
users_table = Table(users_table_name, connection=Core.aws_dynamodb_connection)
users_table.put_item(data={
"login": login,
"password": hashlib.sha256(password.encode("utf-8")).hexdigest(),
"profile": profile,
"registration_date": datetime.now() # PROBLEM IS HERE
})
但是当我运行它时,它失败并出现错误:
But when I run it, it fails with error:
TypeError:值2015-01-12 05:02:57.053131"的不支持类型< type 'datetime.datetime'>"
TypeError: Unsupported type "< type 'datetime.datetime' >" for value "2015-01-12 05:02:57.053131"
我尝试了很多方法,但似乎无法将 datetime
保存到 DynamoDB.顺便说一句,它在 MongoDB 中运行良好.
I've tried a lot of ways, but it seems that it isn't possible to save datetime
to DynamoDB. Btw it works fine in MongoDB.
有什么解决办法吗?
推荐答案
好的,我看到 DynamoDB 不支持任何日期类型.所以唯一的解决方案是使用类unix的时间作为整数,或者将日期保存为字符串.
Okay, I see that DynamoDB does not support any date types. So the only solution is to use unix-like time as integer, or save date as string.
这篇关于是否可以将日期时间保存到 DynamoDB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否可以将日期时间保存到 DynamoDB?


基础教程推荐
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 求两个直方图的卷积 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 包装空间模型 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01