【发布时间】:2020-10-16 20:58:50
【问题描述】:
DETAIL:精度为 2、比例为 2 的字段必须舍入为小于 1 的绝对值。
我正在尝试将 Django 应用程序部署到 Heroku。我的 Django 应用程序使用 Sqlite3,它在我的系统上运行良好。如果您在产品上单击“喜欢”,它会将评级参数更新 1。
这是 Product 模型的 sn-p
class Product(models.Model):
image = models.CharField( max_length= 500, blank = True, help_text= 'Image link' )
title = models.CharField( max_length= 200)
description = models.TextField(blank = True)
price = models.DecimalField(max_digits= 10, decimal_places= 2, blank = True, )
ratings = models.DecimalField(max_digits=10, decimal_places=2, blank= True, default = 0)
Before clicking 'like' the ratings on the product is 4
After clicking 'like' the ratings increases to 5 without any error Result
这就是我更新评分的方式:
if request.method == 'POST':
obj = Product.objects.get(id = i)
obj.ratings += Decimal(1)
obj.save()
但是,在部署到 Heroku 之后,当我点击“喜欢”时,我会收到此错误。
/home/1/ 处的数据错误 数值字段溢出
DETAIL:精度为 2、比例为 2 的字段必须舍入为小于 1 的绝对值。
(/home/1/ 是路线)
我不明白为什么
精度 2,比例 2?
我知道 heroku 可能正在使用 PostgreSQL,正如它在错误页面上所说的那样
但我的 max_digit 是 10,小数位是 2。之前我也是用 max_digits=1000 开始的。还是有数据错误。如何解决此错误?
【问题讨论】:
-
另外,如果它有帮助,当我在 bash 上运行迁移时,我会收到此错误 - django.db.utils.DataError: NUMERIC precision 10000 must be between 1 and 1000
标签: django sqlite django-models heroku-postgres