UUID as primary key for Oracle backend

38 views
Skip to first unread message

Joris Benschop

unread,
Dec 17, 2014, 10:24:02 AM12/17/14
to django...@googlegroups.com
Hi list

I'm trying to use Django 1.7.2 with an Oracle 11.2 backend. THis backend uses RAW(16) fields as primary keys everywhere (it wasnt my choice).
THis is however giving me major headaches, as Django seems to insist on decoding these keys to text.

Here''s my models:
#models.py
from django.db import models
#from uuidfield import UUIDField
from django_extensions.db.fields import UUIDField


class Population(models.Model):
    population_id = UUIDField(primary_key=True)
    population_name = models.CharField(max_length=400,)
    population_cross = models.ForeignKey('PopulationCross')

    class Meta:
        managed = False
        db_table = 'population'

class PopulationCross(models.Model):
    population_cross_id = UUIDField(primary_key=True) 
    population_cross = models.CharField(max_length=100)

    class Meta:
        managed = False
        db_table = 'population_cross'


#--------------------------------------------------------------
#code
from .models import Population


x=Population.objects.all()[0]
x.population_cross
-------------------------------------------------
This last command yields:
django.utils.encoding.DjangoUnicodeDecodeError: 'utf8' codec can't decode byte 0xe9 in position 6: invalid continuation byte. You passed in '\nD\t\x025W\xe9\xc2\xe0SW\x99\x03\n\x0cc' (<type 'str'>)

so for some reason UUIDfield presents itself as a string and it crashes the decode() statement internal in Django

* Using the uuid field module is not an improvement.
* using Char fields also crashes
* using BinaryField works, but may give me misery later on.
 
I apologize if this is a known issue but I spent a day searching and found no solution.
So my questions are:
* Is using BinaryField the only solution here?
* Will BinaryField put in in other trouble elsewhere?
* would the UUIDfield in dev solve my problems?

Any pointer are very welcome. As mentioned, I have no control over the decision to use RAW(16) as primary keys.

Sincerely
Joris

Joris Benschop

unread,
Dec 17, 2014, 11:37:33 AM12/17/14
to django...@googlegroups.com
replying to myself: setting the pk to a binaryfield breaks the usage of django-admin as this tries to force the pk into string as well (options.py function action_checkbox()).
Reply all
Reply to author
Forward
0 new messages