Django "DecimalFields must define a 'decimal_places' attribute."
DECIMAL columns do not permit values larger than the range implied by the column definition. For example, a DECIMAL(3,0) column supports a range of -999 to 999. A DECIMAL(M, D) column permits up to M - D digits to the left of the decimal point.
Mysql Documentation
If you want to accept 10 digits in both number and decimal positions you need to declare 'aaf_1kg_all' like this decimal_places=10)
aaf_1kg_all = models.DecimalField(blank=True, null=True, max_digits=20, decimal_places=10)
Your max_digits
should be greater than the decimal_places
Note that 0.1000000000
uses 10 digits, but 1.0000000000
uses 11 digits. Therefore if you have max_digits=10
and decimal_places=10
, then any numbers greater or equal to 1.0
will give errors.
If you don't need so decimal places, maybe you need something like max_digits=10
, decimal_places=3
. Or if you really need decimal_places=10
, then maybe you need something like max_digits=12
, which would support values less that 1000.
Django 1.9 has added a validator to try to prevent errors like this. See ticket 24636 for more details.
Argument max_digits
must be greater then decimal_places
.
e.g
aaf_1kg_all = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True)