﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
5218	Problems when user provides field name for primary key in Oracle 10 g	catriona.johnson@…	Erin Kelly	"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
"		closed	Database layer (models, ORM)	dev		fixed	oracle primary key AutoField		Accepted	0	0	0	0	0	0
