Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 数据错误:数字字段溢出 详细信息:精度为2、刻度为2的字段必须舍入到小于1的绝对值。_Django_Sqlite_Django Models_Heroku Postgres - Fatal编程技术网

Django 数据错误:数字字段溢出 详细信息:精度为2、刻度为2的字段必须舍入到小于1的绝对值。

Django 数据错误:数字字段溢出 详细信息:精度为2、刻度为2的字段必须舍入到小于1的绝对值。,django,sqlite,django-models,heroku-postgres,Django,Sqlite,Django Models,Heroku Postgres,我正在尝试将Django应用程序部署到Heroku。我的Django应用程序使用Sqlite3,它在我的系统上运行得非常好。如果您在产品上单击“喜欢”,它将按1更新评级参数 下面是产品模型的片段 class Product(models.Model): image = models.CharField( max_length= 500, blank = True, help_text= 'Image link' ) title = models.CharField( max_length=

我正在尝试将Django应用程序部署到Heroku。我的Django应用程序使用Sqlite3,它在我的系统上运行得非常好。如果您在产品上单击“喜欢”,它将按1更新评级参数

下面是产品模型的片段

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)

这就是我更新评级的方式:

if request.method == 'POST':
      obj = Product.objects.get(id = i)
      obj.ratings += Decimal(1)
      obj.save()
然而,在部署到Heroku之后,当我单击“喜欢”时,我得到了这个错误

在/home/1发生数据错误/ 数字字段溢出

详细信息:精度为2、刻度为2的字段必须舍入到小于1的绝对值

(/home/1/是路线)

我不明白为什么

精度2,刻度2

我知道heroku可能正在使用PostgreSQL,正如它在错误页面上所说的那样

但我的最大数字是10,小数点是2。在此之前,我也开始使用max_digits=1000。仍然存在数据错误。如何解决此错误?

已解决 因此,当我在heroku bash上运行migrate命令时,我注意到错误发生在这里

Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying products.0002_auto_20200626_0112...Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.InvalidParameterValue: NUMERIC precision 10000 must be between 1 and 1000
这一行:

正在应用products.0002_auto_20200626_0112…回溯(最近一次呼叫最后一次):

因此,我转到我的迁移文件夹,查看了0002_auto_20200626_0112迁移。事实证明,我已将十进制字段中的最大长度设置为10000。尽管我以前更改并应用了迁移,但该文件的存在本身就导致了错误。因此,我自己手动将该文件上的值更改为值1,错误得到解决。

SOLVED 因此,当我在heroku bash上运行migrate命令时,我注意到错误发生在这里

Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying products.0002_auto_20200626_0112...Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.InvalidParameterValue: NUMERIC precision 10000 must be between 1 and 1000
这一行:

正在应用products.0002_auto_20200626_0112…回溯(最近一次呼叫最后一次):


因此,我转到我的迁移文件夹,查看了0002_auto_20200626_0112迁移。事实证明,我已将十进制字段中的最大长度设置为10000。尽管我以前更改并应用了迁移,但该文件的存在本身就导致了错误。因此,我自己手动将该文件上的值更改为值1,错误得到解决。

如果有帮助,当我在bash上运行migrate时,我会收到此错误-django.db.utils.DataError:数字精度10000必须介于1和1000之间,如果有帮助,在bash上运行migrate时,会出现以下错误-django.db.utils.DataError:数字精度10000必须介于1和1000之间