﻿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
2720	Wrong syntax generated for foreign keys under MySQL	anonymous	nobody	"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."	defect	closed	Database layer (models, ORM)		normal	fixed	innodb foreign key	plesur@… freakboy@… not.com@…	Accepted	1	0	0	1	0	0
