[Fixed]-Django error: [<class 'decimal.InvalidOperation'>]

5๐Ÿ‘

โœ…

I had a similar problem and what I have done to solve it is to make sure that the value I want to save fits in the field, two things:

  1. First, use round(myValueFloat, 4). It is, to reduce the number of decimal numbers I try to save.
  2. Use bigger fields for the values I can not reduce.

23๐Ÿ‘

I recently got this problem myself. The way I thought I knew about decimal fields was wrong in my case.

I thought max_digits=x gives x values for the integer part and decimal_places=y gives y values for the decimal part but I was wrong.

max_digits define the total no. of digits overall and decimal places are part of the max_digits.

for eg. if max_digits=13 and decimal_places=3 then the field will store numeric values up to a billion with 3 precise decimals.

This may help someone who got stuck as I did for the past few hours.

๐Ÿ‘คAnjaan

Leave a comment