开发者

Storing data with leading zeros in an integer column for Django

I need to be able to insert numbers like 098532 into my table. This is the exact same quest开发者_StackOverflow社区ion 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?


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.

num = "051"
int(num)

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜