MySQL alter table generating “error on rename”

倖福魔咒の 提交于 2019-12-13 15:03:59

问题


Here's a print of my error:

mysql> ALTER TABLE Price DROP FOREIGN KEY Id
ERROR 1025 (HY000): Error on rename of '.\testdb\Price' to '.\t
estdb\#sql2-bcc-16' (errno: 152)

I've read this page which suggests that the problem may be due to a left-over table from some earlier alter table error, and recommends you snoop around in your data directory and delete any table with a name such as 'B-xxx.frm'.

My error is similar to this, but there is no '#sql2-bcc-16' in my data directory. And there wouldn't be any artifacts of a previous failed alter table, anyway, because this is just a small test database and I haven't actually altered any tables previously.

EDIT: More info below.

What I really want to do is change an Id (primary key) in another table to be a SMALLINT (instead of a TINYINT). However, THIS Phone table's Id is a foreign key, referencing Id in the other table. So, I believe I need to drop the foreign key of this table before proceeding with the type-change in the primary table. I hope this is clear.

EDIT 2: Tables.

Sale - has Id TINYINT NOT NULL, PRIMARY KEY (Id)

Phone - has Id TINYINT NOT NULL, FOREIGN KEY (Id) REFERENCES Sale (Id)

I would like all Ids in my database to be SMALLINT and not TINYINT. That's my current situation.


回答1:


try with mysql> ALTER TABLE Price DROP Id

Hope it works... Good Luck

I tried with you query mysql> ALTER TABLE Price DROP FOREIGN KEY Id

It executes, but didn't worked!!!

Update:

Use below queries...

mysql> ALTER TABLE Price MODIFY Id SMALLINT

mysql> ALTER TABLE Sale MODIFY Id SMALLINT

mysql> ALTER TABLE Phone MODIFY Id SMALLINT



来源:https://stackoverflow.com/questions/8905856/mysql-alter-table-generating-error-on-rename

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!