so I'm having quite a hard time understanding why this code snippet gives me an
Error: 150 "Foreign key constraint is incorrectly formed"
when trying to create the FK
CREATE TABLE T1 (
t1ID INT AUTO_INCREMENT,
/* ... unrelated columns */
PRIMARY KEY (t1ID)
);
CREATE TABLE T2 (
t3fk INT NOT NULL,
t1fk INT,
/* ... unrelated columns */
CONSTRAINT t2ID PRIMARY KEY (t3fk,t1fk),
FOREIGN KEY (t1fk) REFERENCES T1(t1ID) ON DELETE SET NULL
);
What I'm trying to do is create a c:n relation between t1 and t2 with t2 having a combined PK where (t3fk:null) is a valid identifier
I've searched quite a while for an answer now but I only find results like these, where the FK-column is set to not accept the null value:
MySQL - Foreign key on delete set null in not null field
MySQL: error 150 using ON UPDATE SET NULL and ON DELETE SET NULL, why?
I'm using an InnoDB.
Thank you for your attention (also feedback for future questions is welcome)