Today, I encountered a problem about deleting a foreign key column. I found that:
show create table userfans;
| userfans | CREATE TABLE `userfans` ( `id` int(11) NOT NULL AUTO_INCREMENT, `status` int(11) DEFAULT NULL, `update_time` datetime DEFAULT NULL, `user` int(11) DEFAULT NULL, `fllower` int(11) DEFAULT NULL, `follower` int(11) DEFAULT NULL, PRIMARY KEY (`id`),KEY 'FKF025E60B81E8743E` (`fllower`), KEY `FKF025E60BAFF2360E` (`user`), KEY `FKF025E60BC1B86A61` (`follower`),CONSTRAINT `FKF025E60B81E8743E` FOREIGN KEY(`fllower`) REFERENCES `user` (`id`), CONSTRAINT `FKF025E60BAFF2360E` FOREIGN KEY (`user`) REFERENCES `user` (`id`), CONSTRAINT `FKF025E60BC1B86A61` FOREIGN KEY (`follower`) REFERENCES `user` (`id`)) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 |
At the beginning, I thought: Are you sure you want to delete the key first, then the constraint, and finally the column? Because the foreign key columns of MySQL are different from those of Oracle, MySQL has keys. After trying for a long time, MySQL failed to delete the foreign key columns. It was surprisingly simple:
alter table userfans drop foreign key FKF025E60B81E8743E;
Display:
Query OK, 2 rows affected (0.32 sec)Records: 2 Duplicates: 0 Warnings: 0
It's really a waste of effort to break the shoes!