Changes between Initial Version and Version 1 of Ticket #29845
- Timestamp:
- Oct 12, 2018, 9:38:05 AM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #29845
- Property Triage Stage Unreviewed → Accepted
- Property Summary django orm cast float field to decimal causes MySQL error → Casting FloatField to DecimalField causes MySQL/MariaDB SQL syntax error
-
Ticket #29845 – Description
initial v1 3 3 Seen in django 1.11.16 on MariaDB. 4 4 5 6 5 Model: 7 8 9 6 {{{ 10 7 class MyModel(models.Model): 11 floatfield = models.FloatField('My FloatField')12 decimalfield = models.DecimalField(_("My DecimalField"), decimal_places=2, max_digits=12, validators=[MinValueValidator(Decimal('0.01'))])8 floatfield = models.FloatField() 9 decimalfield = models.DecimalField(decimal_places=2, max_digits=12) 13 10 }}} 14 11 15 16 12 Query: 17 18 19 13 {{{ 20 14 MyModel.objects.all().annotate( 21 22 revenue=Sum(F('floatfield_decimal') * F('decimalfield')))['revenue']23 15 floatfield_decimal=Cast('floatfield', DecimalField(max_digits=8, decimal_places=2))).aggregate( 16 revenue=Sum(F('floatfield_decimal') * F('decimalfield')) 17 )['revenue'] 24 18 }}} 25 19 26 20 Then I see this error: 27 28 29 30 21 {{{ 31 22 {ProgrammingError}(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'numeric(8, 2)) AS `floatfield_decimal`, `myclass`.`decimalfield' at line 1") 32 33 23 }}} 34 24 35 I guess the `numeric` should be `Decimal`... It's not possible to exami te the query further from the debugger.25 I guess the `numeric` should be `Decimal`... It's not possible to examine the query further from the debugger.