ALTER TABLE错误 [英] ALTER TABLE error

查看:135
本文介绍了ALTER TABLE错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释为什么我收到以下错误吗?

Can someone explain to me why I am receiving the following error?

我想使用以下命令将mysql表中的 exerciseID列重命名为 ID

I want to rename the column "exerciseID" to "ID" in a mysql table using the following syntax.

ALTER TABLE  `exercises` CHANGE  `exerciseID`  `ID` INT( 11 ) NOT NULL AUTO_INCREMENT

但是我收到以下错误:

MySQL said: 

#1025 - Error on rename of './balance/#sql-de_110e' to './balance/exercises' (errno: 150)

任何建议将不胜感激

推荐答案

我将检查您是否对该列有任何外键引用。如果是这样,您可能需要删除为该列定义的外部关系,然后重命名,然后使用新的列名将外部键关系放回原处。

I would check to see if you have any foreign key references to that column. If so, you may need to remove the foreign relationships that you have defined for that column, then rename, then place your foreign key relationships back in place with the new column name.

我认为MySQL迷上了这样一个事实,当您重命名时,FK关系不再有效,并且会引发错误。

I think MySQL is getting hung up on the fact that when you rename, the FK relationships are no longer valid and it is throwing an error.

编辑:已确认
MySQL中的FK重命名

您将需要执行以下操作:

You will need to do something like this:

alter table yourTable drop foreign key yourID

这篇关于ALTER TABLE错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆