I have a table which has one column as a foreign key joining to another table.
It’s a cricket question where I have a table called Fixtures and another called Inning.
Inning table has a FixtureId column relates to the Fixture table.
I would expect that If i do a insert on the inning table using a FixtureId that doesn’t relate to a Fixture then it would error but this isn’t the case…
Can anyone explain why this is?
Make sure that you are using the InnoDB storage engine when creating the table. Other storage engines will simply ignore foreign key constraints. (Source)
Example:
The above insert fails with: