MySQL ignores foreign keys constraints in a table representing a many to many relationship
Worth checking that you are using a Storage Engine that supports Foreign Key Constraint checking.

SELECT TABLE_NAME,
       ENGINE
FROM   information_schema.TABLES
WHERE  TABLE_SCHEMA = 'dbname';


The MyISAM Storage engine for instance does not support checking of Foreign Key Constraints. 

If so and you need Foreign Key checks, try changing the storage engine to InnoDB:

ALTER TABLE my_table ENGINE = InnoDB;


If you need this to be the more standard behavior, look at the --default-storage-engine option in your startup.