ALTER TABLE `persons`
ADD CONSTRAINT `persons_ibfk_1` FOREIGN KEY (`location_id`)
REFERENCES `locations` (`id`) ON DELETE SET `location_id` = 1;
谢谢!
答案 0 :(得分:3)
使用ON DELETE SET DEFAULT
(并将1设为默认值)或ON DELETE SET NULL
。
第三个选项是在删除之前手动将所有ID设置为1.