Code

Opened 7 years ago

Closed 7 years ago

#5218 closed (fixed)

Problems when user provides field name for primary key in Oracle 10 g

Reported by: catriona.johnson@… Owned by: ikelly
Component: Database layer (models, ORM) Version: master
Severity: Keywords: oracle primary key AutoField
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Hello

Sorry I wasn't really clear in what I want to achieve. I really just want to call my primary key, in this case, employee_id and have it incremented automatically. But I have the following problem.

from django.db import models

class Employee(models.Model):

employee_id = models.AutoField(max_length=10, primary_key=True)
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20)

and got this output - the table and sequence were created but not the
trigger.

C:\DjangoTraining\PK>python manage.py validate
0 errors found.

C:\DjangoTraining\PK>python manage.py sql test
CREATE TABLE "TEST_EMPLOYEE" (

"EMPLOYEE_ID" NUMBER(11) NOT NULL PRIMARY KEY,
"FIRST_NAME" NVARCHAR2(20) NULL,
"LAST_NAME" NVARCHAR2(20) NULL

)
;
CREATE SEQUENCE TEST_EMPLOYEE_SQ;
CREATE OR REPLACE TRIGGER TEST_EMPLOYEE_TR

BEFORE INSERT ON "TEST_EMPLOYEE"
FOR EACH ROW
WHEN (new.id IS NULL)

BEGIN

SELECT TEST_EMPLOYEE_SQ.nextval INTO :new.id FROM dual;

END;
/

COMMIT;

C:\DjangoTraining\PK>python manage.py syncdb
Creating table test_employee
Traceback (most recent call last):

File "manage.py", line 11, in ?

execute_manager(settings)

File "C:\Python24\Lib\site-packages\django\core\management.py", line

1730, in
execute_manager

execute_from_command_line(action_mapping, argv)

File "C:\Python24\Lib\site-packages\django\core\management.py", line

1621, in
execute_from_command_line

action_mapping[action](int(options.verbosity),

options.interactive)

File "C:\Python24\Lib\site-packages\django\core\management.py", line

554, in s
yncdb

cursor.execute(statement)

File "C:\Python24\Lib\site-packages\django\db\backends\util.py",

line 19, in e
xecute

return self.cursor.execute(sql, params)

File "C:\Python24\Lib\site-packages\django\db\backends\oracle

\base.py", line 1
22, in execute

return Database.Cursor.execute(self, query, params)

cx_Oracle.DatabaseError: ORA-00904: "ID": invalid identifier

I am using the subversion version - from a couple of weeks ago

Thanks
Catriona

Attachments (0)

Change History (3)

comment:1 Changed 7 years ago by ikelly

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to ikelly
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 7 years ago by ikelly

  • Component changed from Uncategorized to Database wrapper
  • Keywords oracle primary key AutoField added
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 7 years ago by ikelly

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [6195]) Fixed #5218: Made Oracle create autoinc triggers using the correct name
of the AutoField column rather than always assume "ID".

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.