Re: Possible bug in django oracle backend - no way to map from model type to oracle NUMBER type.

116 views
Skip to first unread message

Ramiro Morales

unread,
Oct 17, 2012, 1:58:10 PM10/17/12
to django-d...@googlegroups.com
On Wed, Oct 17, 2012 at 7:26 AM, Michał Nowotka <mmm...@gmail.com> wrote:
> Currently I'm working with some oracle legacy db which I would like to
> access using django ORM.
> I have a column of type NUMERIC (without precision and scale) and all
> possible values are kept there (for example, 65, 2.3, 0.0000000050000)
> After running inspectdb django suggested that this column should be of type
> models.DecimalField(unique= True, null=True, max_digits=0,
> decimal_places=-127, blank=True) but this makes little sense since I'm
> getting an error when trying to do syncdb from this model:
>
> Error: One or more models did not validate: DecimalFields require a
> "decimal_places" attribute that is a non-negative integer.
> DecimalFields require a "max_digits" attribute that is a positive integer.
>
> Do you know what type in model will map to NUMBER in oracle?

This is a question for the django-users mailing list. django-dev is exclusively
for the development OF Django not for development WITH Django.

To answer your question. Take a look at this file frm the source code,
it might be fo help:

https://github.com/django/django/blob/master/django/db/backends/oracle/creation.py

--
Ramiro Morales

Ian Kelly

unread,
Oct 17, 2012, 2:16:42 PM10/17/12
to django-d...@googlegroups.com
On Wed, Oct 17, 2012 at 4:26 AM, Michał Nowotka <mmm...@gmail.com> wrote:
> Currently I'm working with some oracle legacy db which I would like to
> access using django ORM.
> I have a column of type NUMERIC (without precision and scale) and all
> possible values are kept there (for example, 65, 2.3, 0.0000000050000)
> After running inspectdb django suggested that this column should be of type
> models.DecimalField(unique= True, null=True, max_digits=0,
> decimal_places=-127, blank=True) but this makes little sense since I'm
> getting an error when trying to do syncdb from this model:
>
> Error: One or more models did not validate: DecimalFields require a
> "decimal_places" attribute that is a non-negative integer.
> DecimalFields require a "max_digits" attribute that is a positive integer.
>
> Do you know what type in model will map to NUMBER in oracle?

There is none. The proper type would be a floating-point
DecimalField, but Django doesn't allow that as the decimal_places
attribute is required. I'm not really sure why that is; maybe the
requirement could be relaxed?

If you don't need a lot of precision, then you could probably get away
with using a FloatField. Otherwise you might want consider creating a
custom field that looks like a FloatField but uses decimals instead of
floats.

Nick Phillips

unread,
Oct 17, 2012, 4:37:12 PM10/17/12
to django-d...@googlegroups.com
On Wed, 2012-10-17 at 12:16 -0600, Ian Kelly wrote:

> > Do you know what type in model will map to NUMBER in oracle?
>
> There is none. The proper type would be a floating-point
> DecimalField, but Django doesn't allow that as the decimal_places
> attribute is required. I'm not really sure why that is; maybe the
> requirement could be relaxed?
>
> If you don't need a lot of precision, then you could probably get away
> with using a FloatField. Otherwise you might want consider creating a
> custom field that looks like a FloatField but uses decimals instead of
> floats.
>

Not if you have a "legacy" database which uses NUMBER, I'm guessing...
I'd have thought the inability to work with any particular common field
type should be a bug, as it could effectively prevent working with
non-managed models altogether.


Cheers,


Nick
--
Nick Phillips / +64 3 479 4195 / nick.p...@otago.ac.nz
# these statements are my own, not those of the University of Otago

Reply all
Reply to author
Forward
0 new messages