3

DETAIL: A field with precision 2, scale 2 must round to an absolute value less than 1.

I am trying to deploy a Django app to Heroku. My Django application uses Sqlite3 and it works perfectly on my system. If you click 'like' on product it will update the ratings parameter by 1.

Here is the snippet of the Product model

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

This is how I'm updating the ratings:

if request.method == 'POST':
      obj = Product.objects.get(id = i)
      obj.ratings += Decimal(1)
      obj.save()

However, after deploying to Heroku, when i click 'like' I get this error.

DataError at /home/1/ numeric field overflow

DETAIL: A field with precision 2, scale 2 must round to an absolute value less than 1.

(/home/1/ is the route)

I don't get why

precision 2, scale 2?

I get that heroku might be using PostgreSQL as it says on the error page

Error page Database info

But my max_digit is 10 and decimal place is 2. Before I also started with max_digits= 1000. There was still a data error. How do I resolve this error?

1
  • Also if it helps, when I run migrate on bash i get this error- django.db.utils.DataError: NUMERIC precision 10000 must be between 1 and 1000 Commented Jun 26, 2020 at 9:41

1 Answer 1

2

SOLVED

So when I ran the migrate command on heroku bash I noticed that the error was occuring arround here

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

This line :

Applying products.0002_auto_20200626_0112...Traceback (most recent call last):

So I went to my migration folder and checked out the 0002_auto_20200626_0112 migration. Turned out that I had set max_length in decimal field at 10000. Even though I changed and applied migration before, the very existence of that file was causing error. SO i changed the value on that file manually myself to a value <1000 , >1 and it the error was resolved.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.