增加外键级联删除:
ALTER TABLE `extends`
ADD CONSTRAINT `extends_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
ON DELETE CASCADE ON UPDATE NO ACTION;
删除外键约束:
ALTER TABLE `extends` DROP FOREIGN KEY `extends_ibfk_1`;
查看完整建表(show create table `extends`):
CREATE TABLE `extends` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`remark` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
CONSTRAINT `extends_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8