On Fri, May 14, 2010 at 8:22 AM, mendes.rich...@gmail.com <
mendes...@gmail.com> wrote:

> [snip]
>
> The problem i'm having is with the following model class with the
> field value:
>
> class Measurement(models.Model):
>        measurement_id = models.AutoField("Measurement
> ID",primary_key=True)
>        value = models.DecimalField(max_digits=10,decimal_places=5)
> [snip other irrelevant fields]
>
> So when i do the following everything works like it should.
>
> m =
>
> Measurement(value=34555,date=date,assay_ontology=ao,parameter=p,measurement_factor=mf,batch=b)
> m.save()
>
> But when i add another digit to the value it gives me the following
> error
> m =
>
> Measurement(value=345556,date=date,assay_ontology=ao,parameter=p,measurement_factor=mf,batch=b)
> m.save()
>
>
Yes. You've specified max_digits=10 and decimal_places=5 for value, so the
maximum allowed digits to the left of the decimal point is 10-5=5. (That is,
five of your ten max_digits are always dedicated to decimal_places digits to
the right of the decimal point, so you can only have up to five on the
left.) Here you are trying to store a number that has six digits to the left
of the decimal point, which won't fit in the DecimalField you have
specified.


Traceback (most recent call last):
>
[traceback snipped]

>  File "/usr/lib/python2.4/decimal.py", line 2267, in _raise_error
>    raise error, explanation
> InvalidOperation: Rescale > prec
>

(Side note more recent Pythons give a somewhat better "explanation":

InvalidOperation: quantize result has too many digits for current context

though that still may not be entirely clear....)


>
> I tried to find out what was going wrong and deleted the complete
> table from the database and did a sycdb with a larger max_digits and
> decimal_places value but that wouldn't help.
>
>
If you want more digits to the left of the decimal point, you need to change
the values of max_digits and decimal_places so that
max_digits-decimal_places is greater than or equal to the number of digits
to you want to allow to the left of the decimal point. Since you have not
said what the new values are that you used, it isn't clear that you
redefined things in a way to allow six digits to the left of the decimal
point.



> i did some further checking on the database, and it seems that there
> is a database problem. When i insert the same values as described
> above i also get an error stating the following:
>
> insert into ratstream_measurement
> values('1143','345556','2008/12/12','1','1','1','5');
> ERROR:  numeric field overflow
> DETAIL:  A field with precision 20, scale 15 must round to an absolute
> value less than 10^5.
>
>
>From this error message I'd guess you changed max_digits to 20 and
decimal_places to 15. This still only allows for 20-15=5 digits to the left
of the decimal point.


> It seems something went wrong with the syncdb but i can't figure out
> what, does anyone know what i'm doing wrong and can assist me helping
> to fix the problem.


If you just want more whole digits, make max_digits higher without changing
decimal_places. You seem to have adjusted both of these values higher in a
way that did not allow for any more whole digits.

Karen
-- 
http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to