Django

Code

Ticket #5218 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

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

Reported by: catriona.johnson@gmail.com Assigned to: ikelly
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords: oracle primary key AutoField
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

Change History

09/14/07 11:51:36 changed by ikelly

  • owner changed from nobody to ikelly.
  • needs_better_patch changed.
  • status changed from new to assigned.
  • needs_tests changed.
  • needs_docs changed.

09/14/07 11:52:43 changed by ikelly

  • keywords set to oracle primary key AutoField.
  • component changed from Uncategorized to Database wrapper.
  • stage changed from Unreviewed to Accepted.

09/14/07 13:12:36 changed by ikelly

  • status changed from assigned to closed.
  • resolution set to fixed.

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


Add/Change #5218 (Problems when user provides field name for primary key in Oracle 10 g)




Change Properties
Action