MySQL foreign key constraint disappearing
Posted
by Bramjam
on Stack Overflow
See other posts from Stack Overflow
or by Bramjam
Published on 2010-05-11T11:18:57Z
Indexed on
2010/05/11
13:54 UTC
Read the original article
Hit count: 171
This is my table:
/* oefenreeks leerplan */
CREATE TABLE leerplan_oefenreeks (
leerplan_oefenreeks_id INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
leerplan_id INT NOT NULL,
oefenreeks_id INT NOT NULL,
plaats INT NOT NULL
);
/* fk */
ALTER TABLE leerplan_oefenreeks ADD CONSTRAINT fk_leerp_oefenr_leerplan
FOREIGN KEY(leerplan_id) REFERENCES leerplan (leerplan_id) ON DELETE CASCADE;
ALTER TABLE leerplan_oefenreeks ADD CONSTRAINT fk_leerp_oefenr_oefenreeks
FOREIGN KEY(oefenreeks_id) REFERENCES oefenreeks (oefenreeks_id) ON DELETE CASCADE;
/* when I execute the nexline, my fk_leerp_oefenr_leerplan constraint vanishes/disappears*/
ALTER TABLE leerplan_oefenreeks ADD CONSTRAINT un_leerp_oefenr UNIQUE(leerplan_id, oefenreeks_id);
ALTER TABLE leerplan_oefenreeks ADD CONSTRAINT un_leerp_oefenr_plaats UNIQUE(leerplan_id, plaats);
When I go and check only 3 constraints exist. fk_leerp_oefenr_leerplan
disappears. I don't understand why this happens.
© Stack Overflow or respective owner