Is it possible to prevent Django from trimming long table names?

I am using Django with an existing Oracle database (i.e. where the tables were NOT created by Django). Therefore, in my models, I need to specify the table name by specifying the value for db_table in the Meta class. I run into problems because the tables that I want to access belong to a different user than those for which I have credentials. I am allowed to view tables (no problem in SQL Developer).

If the Oracle table name would otherwise be more than 30 bytes, Django discards the last four bytes of the name and replaces them with a repeating 4-byte hash of the remaining table names. This is all good and useful for Django tables. It will also normally not be a problem to access tables in existing databases (as in my case), since Oracle itself limited names to 30 bytes.

The problem is that Django does not have a separate means to notify that a table belongs to another user. So I use a temporary solution for the dot syntax (just setting db_table like, for example, "USERNAME.MY_29_BYTE_TABLE_NAMEXXXXXXXX"), but since this causes the table name to be more than 30 bytes in total , Django does its truncated trick and tries to get the table name, which does not exist.

Is there a way to prevent this behavior or another way to specify the user separately from the table name?

+4
source share
1 answer

Truncate is called on the Oracle Django DB server using the quote_name method, which follows the requirements of SQL92 and uses the hard-coded value max_name_length .

You can override this behavior by creating your own database backend or monkeypatch as follows:

from django.db.backends.oracle.base import DatabaseOperations DatabaseOperations.max_name_length = lambda s: <NEW_MAX_VALUE> 

It is not clear why you need more than 30 characters in the table name, since it violates the Oracle Schema Object Naming Rules .

+2
source

All Articles