解决Cannot drop index 'PK_school_schooltype': needed in a foreign key constraint
来源:互联网 发布:四虎影库软件下载安装 编辑:程序博客网 时间:2024/06/04 19:22
今天小编在用mysql数据库去删除一个表的字段时遇到了Cannot drop index 'PK_school_province': needed in a foreign key constraint问题,如下将表的创建贴出来:
CREATE TABLE `school` (
`school_id` int(11) NOT NULL AUTO_INCREMENT,
`school_name` varchar(255) NOT NULL,
`school_pro_id` int(11) NOT NULL,
PRIMARY KEY (`school_id`),
KEY `PK_school_province` (`school_pro_id`),
CONSTRAINT `PK_school_province` FOREIGN KEY (`school_pro_id`) REFERENCES `province` (`province_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2735 DEFAULT CHARSET=utf8
大家都知道KEY与index的意思相近,都是创建索引,现在使用coinstraint来将对字段进行限制,将索引PK_school_province 与外键school_pro_id与外表province表的province_id限制关联(constraint也有索引的意思,on面跟语句),那么现在我想直接删除school_pro_id这个字段,这时,直接使用"alter table school drop column school_pro_id"会出现Cannot drop index 'PK_school_province': needed in a foreign key constraint;大意是不能删除被外键限制的索引PK_school_province。那么这个时候我们需要将外键限制的索引给删除掉,使用”alter table school drop foreign key PK_school_province“就能将PK_school_province删除掉,那么这个时候再使用“alter table school drop column school_pro_id”就可以将school表中的school_pro_id删除掉。
- 解决Cannot drop index 'PK_school_schooltype': needed in a foreign key constraint
- ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint
- Mysql删除表提示Cannot truncate a table referenced in a foreign key constraint解决办法
- MySQL的數據庫drop不了Cannot delete or update a parent row: a foreign key constraint fails
- jbpm4 jbpm4_execution “Cannot delete or update a parent row: a foreign key constraint fails” 异常解决
- 解决1452- Cannot add or update a child rowa foreign key constraint fails问题
- Cannot add or update a child row: a foreign key constraint fails (`mysql`.`ordermx`, CONSTRAINT `kf
- Cannot add or update a child row: a foreign key constraint fails (`tsproduct/product`, CONSTRAINT `F
- 1215-Cannot add foreign key constraint
- migration cannot add foreign key constraint
- 1215 - Cannot add foreign key constraint
- 1215 - Cannot add foreign key constraint
- 1215 Cannot add the foreign key constraint
- 1215-Cannot add the foreign key constraint
- mysql : cannot add foreign key constraint
- a foreign key constraint fails (`school`.`score1`, CONSTRAINT `FK_jqig2u3ktbhovid14i12faasf` FOREIGN
- Could not drop object 'student' because it is referenced by a FOREIGN KEY constraint
- Mysql error 1452 - Cannot add or update a child row: a foreign key constraint fails
- java学习11--语句-for嵌套练习
- Java单例模式
- PHP接收请求的方式
- adnroid 常用的工具类说明
- C++常用的函数
- 解决Cannot drop index 'PK_school_schooltype': needed in a foreign key constraint
- 高版本chrome安装flashplayer debuger后无法使用的问题
- Link 定制网站收藏夹图标
- mongodb基础操作
- 二维码扫描和成像,成像带小图标 自定义色值
- JVM虚拟机
- 字符串排序,特殊字符位置不变
- Fragment详解之六——如何监听fragment中的回退事件与怎样保存fragment状态
- Android入门(30)——第七章 使用WebView在界面中显示网页