ddl: should check child table if parent table does not exists
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
Please answer these questions before submitting your issue. Thanks!
### 1. Minimal reproduce step (Required)
```
mysql> set foreign_key_checks=0;
Query OK, 0 rows affected (0.00 sec)
mysql> create table test.t_fk_child_add (id int primary key, parent_id int, foreign key (parent_id) references test_snapshot_db_create.t_fk_parent(id));
Query OK, 0 rows affected (0.05 sec)
mysql> set foreign_key_checks=1;
Query OK, 0 rows affected (0.00 sec)
mysql> show create table test.t_fk_child_add;
+----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t_fk_child_add | CREATE TABLE `t_fk_child_add` (
`id` int NOT NULL,
`parent_id` int DEFAULT NULL,
PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,
KEY `fk_1` (`parent_id`),
CONSTRAINT `fk_1` FOREIGN KEY (`parent_id`) REFERENCES `test_snapshot_db_create`.`t_fk_parent` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
mysql> insert into test.t_fk_child_add values (1, 1);
Query OK, 1 row affected (0.01 sec)
```
### 2. What did you expect to see? (Required)
cannot insert the child table
### 3. What did you see instead (Required)
insert the child table successfully
### 4. What is your TiDB version? (Required)
release-8.5
Contributor guide
Assessment
This issue has not been assessed yet.