MitchellSalad
MitchellSalad

Reputation: 4281

MySQL alter table generating "error on rename"

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.

Upvotes: 3

Views: 2161

Answers (1)

Fahim Parkar
Fahim Parkar

Reputation: 31647

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

Upvotes: 1

Related Questions