这是我的父表
CREATE TABLE `parent` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`delete` bit(1) NOT NULL,
PRIMARY KEY (`id`,`delete`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
这是我的孩子表
CREATE TABLE `child` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`parent_id` int(11) DEFAULT NULL,
`parent_delete` bit(1) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `parent_if_delete_idx` (`parent_id`,`parent_delete`),
CONSTRAINT `parent_if_delete` FOREIGN KEY (`parent_id`, `parent_delete`) REFERENCES `parent` (`id`, `delete`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
我得到的输出:
+----+--------+
| id | delete |
+----+--------+
| 1 | 0 |
| 2 | 0 |
+----+--------+
CHILD
+-----+-----------+---------------+
| id | parent_id | parent_delete |
+-----+-----------+---------------+
| 1 | 1 | 0 |
| 2 | 2 | 0 |
| 3 | 1 | 0 |
| 4 | 2 | 0 |
+-----+-----------+---------------+
如果我更新父ID和父删除标志,我的子行parent_id会更新,但我的删除标志不会更新。