The problem here is twofold:
1/ Use ID
s for PRIMARY KEY
s
You should be using ID
s for primary keys rather than VARCHAR
s or anything that has any real-world "business meaning". If you want the email
to be unique within the Utilizador
table, the combination of email
and designacaoPOI
to be unique in the POI
table, and the same combination (email
and designacaoPOI
) to be unique in Utilizador_POI
, you should be using UNIQUE KEY
constraints rather than PRIMARY KEY
constraints.
2/ You cannot DELETE CASCADE
on a FOREIGN KEY
that doesn't reference the PRIMARY KEY
In your third table, Utilizador_POI
, you have two FOREIGN KEY
s references POI
. Unfortunately, the PRIMARY KEY
on POI
is a composite key, so MySQL has no idea how to handle a DELETE CASCADE
, as there is not a one-to-one relationship between the FOREIGN KEY
in Utilizador_POI
and the PRIMARY KEY
of POI
.
If you change your tables to all have a PRIMARY KEY
of ID
, as follows:
CREATE TABLE blah (
id INT(9) AUTO_INCREMENT NOT NULL
....
PRIMARY KEY (id)
);
Then you can reference each table by ID
, and both your FOREIGN KEY
s and DELETE CASCADE
s will work.