Opened 12 years ago

Closed 8 years ago

#18514 closed Bug (duplicate)

Creating sequences fails with Oracle 01741 error on custom table name with quotes

Reported by: obmuc Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2
Severity: Normal Keywords: oracle
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Using a custom table name with Oracle, and entering the full-qualified oracle schema + table name with quotes, is resulting in an Oracle 17141 error when running syncdb: "illegal zero-length identifier". The all-knowing Google indicates this is due to an empty string ("") being passed to Oracle.

Example Model:

class MyModel(models.Model):
	a_field = models.CharField(max_length=1000, blank=True, null=True)
	
	class Meta:
		db_table = u'"ORACLE_SCHEMA"."DESIRED_TABLE_NAME"'

Executing the syncdb management command to create that table results in the following:

$ ./manage.py syncdb
Creating table "ORACLE_SCHEMA"."DESIRED_TABLE_NAME"
Traceback (most recent call last):
  File "./manage.py", line 11, in <module>
    execute_manager(settings)
  File "[ intentionally obscured ]/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "[ intentionally obscured ]/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "[ intentionally obscured ]/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "[ intentionally obscured ]/lib/python2.6/site-packages/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "[ intentionally obscured ]/lib/python2.6/site-packages/django/core/management/base.py", line 351, in handle
    return self.handle_noargs(**options)
  File "[ intentionally obscured ]/lib/python2.6/site-packages/django/core/management/commands/syncdb.py", line 99, in handle_noargs
    cursor.execute(statement)
  File "[ intentionally obscured ]/lib/python2.6/site-packages/django/db/backends/util.py", line 15, in execute
    return self.cursor.execute(sql, params)
  File "[ intentionally obscured ]/lib/python2.6/site-packages/django/db/backends/oracle/base.py", line 595, in execute
    return self.cursor.execute(query, self._param_generator(params))
django.db.utils.DatabaseError: ORA-01741: illegal zero-length identifier
ORA-06512: at line 8

The table is otherwise usable with the Django ORM once created - just errors on attempt to create via syncdb.

Change History (2)

comment:1 by Aymeric Augustin, 12 years ago

Keywords: oracle added
Triage Stage: UnreviewedAccepted

comment:2 by Tim Graham, 8 years ago

Resolution: duplicate
Status: newclosed
Summary: Syncdb + Oracle + custom table name with quotes = Oracle 01741 errorCreating sequences fails with Oracle 01741 error on custom table name with quotes

The offending query is:

BEGIN
    SELECT COUNT(1) INTO i FROM USER_SEQUENCES
        WHERE SEQUENCE_NAME = '"DJANGOTEST"."TABLE_NAME"_SQ';
    IF i = 0 THEN
        EXECUTE IMMEDIATE 'CREATE SEQUENCE ""DJANGOTEST"."TABLE_NAME"_SQ"';
    END IF;
END;

Looks like this is fixed by #27458.

Note: See TracTickets for help on using tickets.
Back to Top