Opened 19 years ago
Last modified 17 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 (
idinteger AUTO_INCREMENT NOT NULL PRIMARY KEY,
execution_timedatetime NOT NULL,
periodinteger NOT NULL,
system_script_idinteger NOT NULL REFERENCESsystem_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 (
idinteger AUTO_INCREMENT NOT NULL PRIMARY KEY,
system_script_idinteger NOT NULL,
execution_timedatetime NOT NULL,
periodinteger NOT NULL,
foreign key (system_script_id) referencessystem_script(id)
);
Using this syntax, all of my foreign key constraints seem to be successfully created.