MySQL删除foreign key_ERROR 1025 (HY000): Error on rename of './test_20180206/cc' to './test_20180206/#sql2-9ac-e' (errno: 152)
问题背景描述:
首先,创建了一个主表,具有以下数据结构:
mysql> describe aa;
+-------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+----------------+
| ID | int() | NO | PRI | NULL | auto_increment |
| SecID | int() | NO | UNI | NULL | |
| name | char() | NO | | NULL | |
| sex | char() | YES | | femal | |
+-------+----------+------+-----+---------+----------------+
rows in set (0.01 sec)
然后,创建了一个从表,通过外键,与表aa的SecID属性关联起来:
mysql> create table bb //创建表bb
-> (SecID int() unique not null,
-> room_num int() not null,
-> extra binary default )
-> engine=InnoDB;
Query OK, rows affected (0.10 sec)
mysql> alter table bb add foreign key(SecID) references aa(SecID); //添加外键
Query OK, rows affected (0.14 sec)
Records: Duplicates: Warnings:
执行对bb表的外键删除操作,出现以下error:
mysql> alter table cc drop foreign key SecID;
ERROR (HY000): Error on rename of './test_20180206/cc' to './test_20180206/#sql2-9ac-e' (errno: )
经过分析,笔者发现是因为创建外键时,外键名与属性名一样导致的。
因此,在创建外键时,最好加上外键的别名设置,以便于外键属性的修改或删除,命令如下:
mysql> alter table cc add constraint SECID foreign key(SecID) references aa(SecID);
mysql> alter table cc drop foreign key SECID;
Query OK, rows affected (0.16 sec)
Records: Duplicates: Warnings:
目前没有找到外键名与属性名一致时,删除外键的彻底解决方法。
可以通过命令CREATE TABLE SELECT的命令将表结构及其数据进行备份,此时外键属性是不会被复制的,就可以根据新表重新进行可靠的外键设置操作。
MySQL删除foreign key_ERROR 1025 (HY000): Error on rename of './test_20180206/cc' to './test_20180206/#sql2-9ac-e' (errno: 152)的更多相关文章
- MySQL主从复制中断,报“Error on master: message (format)='Cannot delete or update a parent row: a foreign key constraint fails' error code=1217” 错误
前几天,发现从库挂了,具体报错信息如下: 分析思路 1. 因为我采用的是选择性复制,只针对以下几个库进行复制: card,upay,deal,monitor,collect.所以,不太可能出现对于sa ...
- 【MYSQL用户创建报错】ERROR 1396 (HY000): Operation CREATE USER failed for 'user1'@'%'
原文参考自:http://blog.csdn.net/u011575570/article/details/51438841 1.创建用户的时候报错ERROR 1396 (HY000): Operat ...
- mysql安装过程中出现错误ERROR 1820 (HY000): You must SET PASSWORD before executing this statement解决
mysql安装过程中出现错误ERROR 1820 (HY000): You must SET PASSWORD before executing this statement解决 最近新装好的my ...
- mysql root用户kill connection报ERROR 1095 (HY000): You are not owner of thread N
今日某系统mysql root用户kill connection时报ERROR 1095 (HY000): You are not owner of thread N 按说通过root用户具有supe ...
- 线上问题 - MySQL SQL state [HY000]; error code [1366]
一.问题描述 另外一个系统调用服务接口api:/xxx/create?aName=&time=&...,数据没有保存成功提示SQL state [HY000]; error code ...
- mysql删除有外链索引数据,Cannot delete or update a parent row: a foreign key constraint fails 问题的解决办法
mysql删除有外链索引数据Cannot delete or update a parent row: a foreign key constraint fails 问题的解决办法查询:DELETE ...
- Mysql插入中文时提示:ERROR 1366 (HY000): Incorrect string value: '\xE5\x8F\xB0\xE5\xBC\x8F...' fo
Mysql插入数据时提示:ERROR 1366 (HY000): Incorrect string value: ‘\xE5\x8F\xB0\xE5\xBC\x8F…’ fo 分析如下: 首先通过语句 ...
- mysql 链接数满了的错误 ERROR 1040 (HY000): Too many connections
mysql 链接数满了的错误 ERROR 1040 (HY000): Too many connections 第一种处理方式: ./mysql -u root -p 登录成功后执行以下语句查询当前的 ...
- ERROR 1010 (HY000): Error dropping database (can't rmdir './test/', errno: 17)
在删除数据库的时候报标题所示错误 mysql> drop database test; ERROR (HY000): Error dropping database (can't rmdir ' ...
随机推荐
- 正则RegExp序2
1.var reg=/./ var reg=/\./ 前者代表任意一个字符而后面代表这个字符串中得有一个. 2.?的使用 如果单独的一个字符后面带? var reg=/\d?/ /n?/ 代表 ...
- 工具包分享-常用工具。by-某某
下载地址: 链接:http://pan.baidu.com/s/1hsseqm4 密码:a6rc 里面的工具全部来自互联网,本人不是工具的生产者,只是它的收集工. 都是一些很常用,顺手的工具,仅用于技 ...
- Ubuntu-1604-LTS在虚拟机设置分辨率
在虚拟机中安装ubuntu系统时,有时系统的界面并不同虚拟机展示的匹配,需要我们进行调整.不用那么多废话,直接看图:
- 14 - How to check replication status
The people using PostgreSQL and the Streaming Replication feature seem to ask many of the same quest ...
- oracle 约束与索引
1.约束 1.not null(列表不为空) create table 表名(列名1 列表属性2 not null,列名1 列表属性2 not null); 2.unique(列表不能重复) crea ...
- ZPW-2000电气绝缘移频轨道电路
1.该轨道电路是个什么样子?(图片) 整个轨道电路不仅都在室外,其中还包括室内设备.其中室内设备包括发送器.接收器和衰耗盒.室内设备和室外设备通过一根电缆相连. 机柜 2.移频轨道电路有什么作用? z ...
- pc端 页面 显示在手机 一行控制适配问题
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
- 汇编-13.0-int指令
1.int指令 int指令的格式为:int n,n为中断类型码,它的功能是引发中断过程. 执行int n指令,相当于引发一个中断号为n的中断过程. (1).取中断类型码n: (2).标志寄存器入栈,I ...
- 第一次接触Android Studio
生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4390905.html
- ASP.NET微信支付XXE漏洞修复
1. XXE场景 关于XML解析存在的安全问题指引 微信支付商户,最近暴露的XML外部实体注入漏洞(XML External Entity Injection,简称 XXE),该安全问题是由XML组件 ...