MySQL:在 PHPMyAdmin 中删除索引后无法重新创建表(错误号:150)

问题描述 投票:0回答:0

我可以看到很多关于这个的帖子,但显然没有一个与我的具体问题相似。

我创建了我的表:

CREATE TABLE ANOTHER_TABLE (ID_ANOTHER_TABLE BIGINT PRIMARY KEY);
create table EXAMPLE (TYPE varchar(10) not null, EXAMPLE_NUMBER integer default '0', ID_ANOTHER_TABLE bigint not null, primary key (TYPE, ID_ANOTHER_TABLE)) ENGINE=InnoDB;
alter table EXAMPLE add index FK_h9owxl7oyju8ue8b97u7ldei (ID_ANOTHER_TABLE), add constraint FK_h9owxl7oyju8ue8b97u7ldei foreign key (ID_ANOTHER_TABLE) references ANOTHER_TABLE (ID_ANOTHER_TABLE) on delete cascade;

然后我想放弃它重新创建它有很多变化。而不是简单地删除它,在 PHPMyAdmin 中我进入了表结构页面,我首先点击从外键中删除索引(我误以为我正在删除外键):

ALTER TABLE `EXAMPLE` DROP INDEX `FK_h9owxl7oyju8ue8b97u7ldei`;

它下降了,虽然它不应该。在命令行中我会收到错误

Cannot drop index 'FK_h9owxl7oyju8ue8b97u7ldei6': needed in a foreign key constraint.

但是显示没有报错,显然是执行成功了,然后我接着点击drop the primary key:

ALTER TABLE `EXAMPLE` DROP PRIMARY KEY;

但是这次报错:

#1025 - Error on rename of './mydb/#sql-b6bd_2a9e7' to './mydb/EXAMPLE' (errno: 150)

然后桌子消失了。如果我试图放下它,我会得到

#1051 - Unknown table 'EXAMPLE'
.

如果我再次尝试创建表格,这就是我得到的:

#1005 - Can't create table 'mydb.EXAMPLE' (errno: 150) (Details…)
230228 14:43:40 Error in foreign key constraint of table mydb/EXAMPLE:
there is no index in the table which would contain
the columns as the first columns, or the data types in the
table do not match the ones in the referenced table
or one of the ON ... SET NULL columns is declared NOT NULL. Constraint:
,
  CONSTRAINT "FK_h9owxl7oyju8ue8b97u7ldei" FOREIGN KEY ("ID_ANOTHER_TABLE") REFERENCES "ANOTHER_TABLE" ("ID_ANOTHER_TABLE") ON DELETE CASCADE

显然约束卡住了,我不能删除它,因为表不再存在。 有什么办法可以在不删除模式的情况下清理它

MySQL 5.5.62 PHPMyAdmin 5.0.1

谢谢

mysql phpmyadmin
© www.soinside.com 2019 - 2024. All rights reserved.