gpt4 book ai didi

Django:用于 MongoDB 的长字段 (BigIntegerField)

转载 作者:可可西里 更新时间:2023-11-01 09:15:48 26 4
gpt4 key购买 nike

我想分配一个模型字段来存储 MongoDB 中的 Long 整数类型。我已经用 BigIntegerField 试过了,但它仍然作为 Integer 字段保存在 MongoDB 中。我试过使用:

models.BigIntegerField()

我应该使用哪个模型字段?注意:我将 django-nonrel 用于 DJango-MongoDB 关系。

最佳答案

您是否节省了足够大的值(value)?您使用的 python 版本也可能很重要。来自 API 文档:

A Python int will be saved as a BSON int32 or BSON int64 depending on its size. A BSON int32 will always decode to a Python int. In Python 2.x a BSON int64 will always decode to a Python long. In Python 3.x a BSON int64 will decode to a Python int since there is no longer a long type.

此外,python long 应始终映射到 BSON 64 位整数:

http://api.mongodb.org/python/2.3rc1/api/bson/son.html

关于Django:用于 MongoDB 的长字段 (BigIntegerField),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12138412/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com