5

I am using django with oracle database. I have a model that uses django-modeltranslation. When I add text for more than one language oracle database throws ORA-22284: duplicate LONG binds are not supported error. How can I solve it? I am new to StackOverFlow. Please, let me know if my question is not detailed well.

This is my model:

class About(models.Model):
    image = models.ImageField(upload_to='about', verbose_name=_('Image'))
    text = models.TextField(verbose_name=_("Text"))
    phone = models.CharField(max_length=50, verbose_name="Phone")
    address = models.CharField(max_length=255, verbose_name=_("Address"))

class Meta:
    verbose_name = _("About")
    verbose_name_plural = _("About")

def __str__(self):
    return str(_('About AzeriCard'))

and this is translations.py

from app.models import *
from modeltranslation.translator import translator, TranslationOptions

class AboutTrans(TranslationOptions):
    fields = ('text', 'address')
Alihaydar Gubatov
  • 988
  • 1
  • 12
  • 27
  • It's not your Python code that's the issue. One of your columns have the data type `long` (I'm guessing `text` or `address`, which Oracle doesn't support binding with. You could use a function to return the result instead but it's unnecessarily complicated, especially with an ORM. If you need a field more than 4,000 bytes I'd highly recommend using CLOBs instead. – Ben Oct 17 '17 at 20:52
  • @Ben, I have to do it in database level, right? Can't I change how django-orm "translates" TextField into SQL code? I know that it can be solved at database level but I need to make django code work without touching the database. – Alihaydar Gubatov Oct 17 '17 at 21:04
  • 1
    If my assumption is correct that one of the columns is a `long` then yes, you have to make changes at the database level. It's [only provided for backward compatibility](https://docs.oracle.com/database/121/SQLRF/sql_elements001.htm#SQLRF30020) now the docs say _"Do not create tables with LONG columns. Use LOB columns (CLOB, NCLOB, BLOB) instead. LONG columns are supported only for backward compatibility."_ – Ben Oct 17 '17 at 21:07

1 Answers1

1

recenly working with Oracle and Django ORM, using multiples TextFields and assing the same value (longer than 2000 characters). Oracle crash with ORA-22284 error.

class Object(models.Model):
    text = models.TextField(verbose_name=_("Text"))
    text1 = models.TextField(verbose_name=_("Text1"))


@receiver(pre_save, sender=Object)
def add_spaces_to_textfield(sender, instance, **kwargs):
    if instance.text == instance.text1:
         instance.text1 = instance.text1 + " "

In your case with modeltranslation, you can do similar, with the fields, text, text_xx, text_yy

josemlp
  • 496
  • 3
  • 5