请教一下错误
mysql> CREATE TABLE TB3(
-> id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
-> pname varchar(20) NOT NULL
-> );
Query OK, 0 rows affected (0.01 sec)
mysql> CREATE TABLE TB4(
-> id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
-> username VARCHAR(20) NOT NULL,
-> pid SMALLINT UNSIGNED,
-> FOREIGN KEY(pid) REFERENCES TB3 (id)
-> );
Query OK, 0 rows affected (0.01 sec)
mysql> INSERT TB1(pname) VALUES('A');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT TB1(pname) VALUES('B');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT TB1(pname) VALUES('X');
Query OK, 1 row affected (0.01 sec)
mysql> SELECT * FROM TB1;
+----+-------+
| id | pname |
+----+-------+
| 1 | A |
| 2 | B |
| 3 | X |
+----+-------+
3 rows in set (0.00 sec)
mysql> INSERT TB2(username,pid) VALUES('LOIS',1)
-> ;
ERROR 1146 (42S02): Table 'test.tb2' doesn't exist
mysql> INSERT TB4(username,pid) VALUES('LOIS',1)
-> ;
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`test`.`tb4`, CONSTRAINT `tb4_ibfk_1` FOREIGN KEY (`pid`) REFERENCES `tb3` (`id`))
为什么会报错啊??求助各位大神