MySQL 更改表生成“重命名错误”
这是我的错误的打印:
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)
我已阅读 this页 这表明问题可能是由于某些早期更改表错误留下的表造成的,并建议您在数据目录中窥探并删除名称为“B-xxx.frm”的任何表'。
我的错误与此类似,但我的数据目录中没有“#sql2-bcc-16”。无论如何,不会有以前失败的更改表的任何工件,因为这只是一个小型测试数据库,而且我之前实际上没有更改任何表。
编辑:下面有更多信息。
我真正想做的是将另一个表中的 Id (主键)更改为 SMALLINT (而不是 TINYINT)。但是,此 Phone 表的 Id 是外键,引用另一个表中的 Id。因此,我相信在继续主表中的类型更改之前需要删除该表的外键。我希望这一点很清楚。
编辑2:表格。
销售 - 具有 Id TINYINT NOT NULL,PRIMARY KEY (Id)
电话 - 具有 Id TINYINT NOT NULL,FOREIGN KEY (Id) 参考 销售 (Id)
我希望数据库中的所有 Id 均为 SMALLINT 而不是 TINYINT。这就是我目前的情况。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
mysql> ALTER TABLE Price DROP Id
希望它能起作用...祝你好运,
我尝试用你的查询
mysql>; ALTER TABLE Price DROP FOREIGN KEY Id
它执行了,但没有起作用!
更新:
使用以下查询...
mysql> ALTER TABLE Price MODIFY Id SMALLINT
mysql> ALTER TABLE Sale MODIFY Id SMALLINT
mysql>更改表电话修改 Id SMALLINT
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