在 Django 的整数列中存储带有前导零的数据
我需要能够将 098532
这样的数字插入到我的表格中。这与这个完全相同但实际上我需要用前导零来存储它,因为我将使用这些数据进行 3rd 方 API 调用。
给出的答案是格式化输出,但这并不能真正解决我的问题。
将列的数据类型更改为 CHAR 字段的最佳解决方案是?
I need to be able to insert numbers like 098532
into my table. This is the exact same question as this but I actually need to store it with the leading zeros as I will be using the data for 3rd party API calls.
The given answer was to format the output which doesn't really solve my problem.
Is the best solution to change the datatype of the column to a CHAR
field?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为最好的选择是将其作为字符串存储在 charfield 中,然后在需要其他内容时将其转换。
即
如果您需要它作为 int 。您能否提供更多关于 api 期望的信息以及为什么需要前导零?
I think your best bet is to store it as a string in a charfield and then cast it when you need something else.
i.e.
if you need it as an int. Could you give a little more information about what the api expects and why you need the leading zeroes?