简体   繁体   English

MySQL alter table生成“重命名时出错”

[英]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'. 我已阅读此页面该页面表明该问题可能是由于某些早期alter table错误导致的剩余表,并建议您在数据目录中窥探并删除任何名称为“B-xxx”的表。 FRM”。

My error is similar to this, but there is no '#sql2-bcc-16' in my data directory. 我的错误类似于此,但我的数据目录中没有'#sql2-bcc-16'。 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. 无论如何,不​​会有任何先前失败的alter table的工件,因为这只是一个小的测试数据库而且我之前没有实际更改任何表。

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). 我真正想要做的是将另一个表中的Id(主键)更改为SMALLINT(而不是TINYINT)。 However, THIS Phone table's Id is a foreign key, referencing Id in the other table. 但是,此电话表的Id是外键,在另一个表中引用Id。 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. 编辑2:表格。

Sale - has Id TINYINT NOT NULL, PRIMARY KEY (Id) 销售 - 有Id TINYINT NOT NULL,主要密钥(Id)

Phone - has Id TINYINT NOT NULL, FOREIGN KEY (Id) REFERENCES Sale (Id) 电话 - 有Id TINYINT NOT NULL,外键(Id)参考销售(Id)

I would like all Ids in my database to be SMALLINT and not TINYINT. 我希望我的数据库中的所有ID都是SMALLINT而不是TINYINT。 That's my current situation. 那是我目前的情况。

try with mysql> ALTER TABLE Price DROP Id 尝试使用mysql> ALTER TABLE Price DROP Id

Hope it works... Good Luck 希望它有效......祝你好运

I tried with you query mysql> ALTER TABLE Price DROP FOREIGN KEY Id 我试过你查询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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM