In a django project I'm trying to store a calculated decimal value, but it fails for some strange reason. My model looks something like:
class FancyModel(models.Model):
fancy_field = models.DecimalField(max_digits=10, decimal_places=3, null=True, blank=True)
Sometimes, rather often actually, it crashes on save:
django.db.utils.IntegrityError: CHECK constraint failed: myapp_fancy_model
which I found out after some digging was caused by this validation:
django.core.exceptions.ValidationError: {'fancy_field': ['Ensure that there are no more than 2 decimal places.']}
I've dumped the values of the actual model, and it seems ok to me:
{'fancy_field': 3.26 }
I cannot see how this would fail. Sometimes it works fine, other times it crashes. I've tried to use the round-method, like:
model_instance.fancy_model = round(floating_value, 2)
but it still fails.