Created
December 12, 2019 17:11
-
-
Save nilsmeyer/dcb2cf17b4d8347e0ef0561e0c9b544e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MariaDB [test]> create table t1 (id int unsigned not null auto_increment primary key); | |
Query OK, 0 rows affected (0.027 sec) | |
MariaDB [test]> create table t2 (id int unsigned not null auto_increment primary key, t1_id int unsigned not null, foreign key(t1_id) references t1(id)); | |
Query OK, 0 rows affected (0.040 sec) | |
MariaDB [test]> insert into t2 (t1_id) values (1); | |
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`)) | |
MariaDB [test]> set foreign_key_checks=0; | |
Query OK, 0 rows affected (0.000 sec) | |
MariaDB [test]> insert into t2 (t1_id) values (1); | |
Query OK, 1 row affected (0.007 sec) | |
MariaDB [test]> set foreign_key_checks=1; | |
Query OK, 0 rows affected (0.000 sec) | |
MariaDB [test]> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment