Opened 17 years ago
Closed 17 years ago
#5218 closed (fixed)
Problems when user provides field name for primary key in Oracle 10 g
Reported by: | Owned by: | Erin Kelly | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
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: | no | UI/UX: | no |
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
Change History (3)
comment:1 by , 17 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 17 years ago
Component: | Uncategorized → Database wrapper |
---|---|
Keywords: | oracle primary key AutoField added |
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
(In [6195]) Fixed #5218: Made Oracle create autoinc triggers using the correct name
of the AutoField column rather than always assume "ID".