Opened 18 years ago

Last modified 16 years ago

#2720 closed defect

Wrong syntax generated for foreign keys under MySQL/InnoDB 5.0.22 — at Initial Version

Reported by: anonymous Owned by: nobody
Component: Database layer (models, ORM) Version:
Severity: normal Keywords: innodb foreign key
Cc: plesur@…, freakboy@…, not.com@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Django uses the following syntax to define foreign keys under MySQL/InnoDB:

CREATE TABLE system_script_queue (

id integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
execution_time datetime NOT NULL,
period integer NOT NULL,
system_script_id integer NOT NULL REFERENCES system_script (id)

);

Using that syntax, maybe 1/3 of my foreign key constraints are being ignored by the DB.

If I'm reading this tech note correctly (http://dev.mysql.com/doc/refman/5.0/en/example-foreign-keys.html), that's the wrong syntax to use. The correct syntax is this one:

CREATE TABLE system_script_queue (

id integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
system_script_id integer NOT NULL,
execution_time datetime NOT NULL,
period integer NOT NULL,
foreign key (system_script_id) references system_script (id)

);

Using this syntax, all of my foreign key constraints seem to be successfully created.

Change History (0)

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