The foreign key does not stop me from entering MySQL data

I have a table that has one column as a foreign key connecting another table. This is a cricket issue, where I have a table called "Lights" and another - "Inning".

The Inning table has a FixtureId column related to the Fixture table.

I would expect that if I do an insert in the inning table using a FixtureId that is not related to Fixture, then it will be an error, but it is not ...

Can someone explain why this is?

+3
source share
2 answers

, InnoDB . . ()

:

CREATE TABLE a (
     id INT AUTO_INCREMENT PRIMARY KEY
) ENGINE=INNODB;

CREATE TABLE b (
     id INT AUTO_INCREMENT PRIMARY KEY,
     a_id INT,
     FOREIGN KEY (a_id) REFERENCES a(id)
) ENGINE=INNODB;

INSERT INTO b (id, a_id) VALUES(NULL, 1);

:

1452 (23000): : ...

+6

im , , SQL-? ( ), , , ?

0

Source: https://habr.com/ru/post/1734258/


All Articles