I am not able to add foreign key constraint ON DELETE CASCADE ON UPDATE CASCADE.
I use two simple tables.
TAB1 has 2 columns: ID int(10) unsigned NOT NULL AUTOINCREMENT, and data int(10) unsigned NOT NULL.
TAB2 has 2 columns: ID int(10) unsigned NOT NULL AUTOINCREMENT, and FK int(10) unsigned NOT NULL.
I can create foreign key fron column FK in table TAB2 on column ID in TAB1 with "ON DELETE RESTRICT".
But i am not able to create such a key with "ON DELETE CASCADE" or "ON DELETE SET NULL". The errors is "#1215 - Cannot add foreign key constraint".
I have tried with signed, NULL, int(4)... ets. Do not unserstand where is the error.
The only FOREIGN KEY(tcfkowner
), which i managed to create with CASCADE a month before is in TABLE tcalendar
ADD REFERENCES tuser (tcid
).
I unserstand that on DELETE CASCADE means that if i delete user, the row in calendar pointing to the user will also be deleted.
Instead the foreign key seems restricts deletion of his parent: i am not able to delete any row in TABLE tuser
which is pointed by FOREIGN KEY(tcfkowner
) from TABLE tcalendar
. The error message:
" MySQL said: Documentation