Home > Mobile >  any idea how to save a data string of int which is more than the max length into sql database?
any idea how to save a data string of int which is more than the max length into sql database?

Time:12-13

 IBAN = Required(str)
    Credit_Card_number = Required(int)
    CV2 = Required(int)
"credit_card_number": "2221597849919620",

with db_session:
    with open('user_data.json') as f:

 for i in data:
            Card(FirstName=i['firstName'], LastName=i['lastName'], Age=i['age'], IBAN=i['iban'], Credit_Card_number=i['credit_card_number'],....... 

ValueError: Value 2221597849919620 of attr Card.Credit_Card_number is greater than the maximum allowed value 2147483647

So how do i fix this to allow it be sent into mysql using the pony orm and python.

CodePudding user response:

You should be using a long integer column type for the credit_card_number field. On many databases (including MySQL, SQL Server, and Postgres), this would be a BIGINT type column.

CodePudding user response:

a conversion is only necessary, if you need to manipulate the json data and don't want to use the given database tools or build your own.

the extracting of json data isn't that hard, so you keep the json format.

python can hanlde long very well

Credit_Card_number = int
Credit_Card_number = 2221597849919620
print(Credit_Card_number)
print(type(Credit_Card_number))

results in

2221597849919620
<class 'int'>

so the line

Credit_Card_number = Required(int)

reduce the possible numbers.

simply don't use it and perform a check with int(2221597849919620)

  • Related