I have an intersecton table to record many-to-many relationships among three tables. Each combination must be unique, so I have a unique index on the three fields. However, using the PHP application I wrote to edit this data, a user can insert the same combination multiple times. No exception is thrown even though the SQL insert is in a try-catch block, and the records are inserted with no enforcement of the unique key.
Is there something wrong with my table DLL?
CREATE TABLE `diagnosis_x_category` (
`diagnosis_id` int(11) DEFAULT NULL,
`category_id` int(11) DEFAULT NULL,
`subcategory_id` int(11) DEFAULT NULL,
UNIQUE KEY `uniq_diagnosis_x_category_key` (`diagnosis_id`,`category_id`,`subcategory_id`) USING BTREE,
CONSTRAINT `diagnosis_x_category_ibfk_1` FOREIGN KEY (`diagnosis_id`) REFERENCES `nd_diagnosis` (`id`),
CONSTRAINT `diagnosis_x_category_ibfk_2` FOREIGN KEY (`category_id`) REFERENCES `nd_category` (`id`),
CONSTRAINT `diagnosis_x_category_ibfk_3` FOREIGN KEY (`subcategory_id`) REFERENCES `nd_subcategory` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
NOT NULL
in an intersection table?