Monday, January 31, 2011

Re: working django with existing database

On Jan 31, 12:20 am, arief nur andono <>
> class TempJmlGangguanPyl(models.Model):
>     singkatpyl = models.CharField(max_length=4, blank=True)
>     singkatgrd = models.CharField(max_length=4, blank=True)
>     jumlah_gangguan = models.DecimalField(null=True, max_digits=0,
> decimal_places=-127, blank=True)
>     lama_gangguan = models.DecimalField(null=True, max_digits=0,
> decimal_places=-127, blank=True)
>     class Meta:
>         db_table = u'temp_jml_gangguan_pyl'

It appears that your numeric columns are all decimal-precision
floating-point (i.e. "FLOAT" or "NUMBER" with no precision or scale
specified), which is a bit of a corner case. The basic problem is
that Django core has no field for this. DecimalField can only handle
fixed-point, and FloatField uses binary precision. If these columns
are actually used to store fixed-point data, you could manually update
the generated models (or preferably the original schema) with the
actual precision and scale of the data. If they are truly floating-
point, then you would probably need to write a custom DecimalField
class. I wouldn't recommend changing them to FloatField in any case,
because that could result in a loss of precision.

A similar problem can be encountered with "NUMBER(p, s)" columns where
s < 0 or s > p. Both these scenarios are perfectly valid in Oracle,
but are (somewhat arbitrarily) disallowed by the DecimalField

I'll make a note of this. At the very least, there should be a more
descriptive error message for when this comes up.


You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment