0

I have table my_transitions and I am trying to delete field called myStage.

I am using this command:

alter table `my_transitions` drop `myStage`

I am seeing this error:

Key column 'myStage' doesn't exist in table

But when I list all fields using this command: describe my_transitions

I can see

id  bigint(20) unsigned NO  PRI NULL    auto_increment
myStage varchar(255)    NO  MUL NULL    
updated_at  timestamp   YES     NULL    

Anyone can see if I am doing something wrong?

EDIT:

If I run show create table my_transitions;, I am getting:

CREATE TABLE `my_transitions` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `myStage` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `myStage1` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_stage_combination` (`myStage`,`myStage1`),
  KEY `my_transitions_myStage` (`myStage`),
  KEY `my_transitions_myStage1` (`myStage1`)
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
4

2 回答 2

1

我已经通过首先删除唯一键来解决它 ALTER TABLE my_transitions DROP INDEX unique_stage_combination;

如果列是 Maria DB 10.5.8 中索引键的一部分,则似乎无法删除该列。

于 2021-04-05T00:23:24.153 回答
1

这是 MariaDB 中的一个特殊错误。它影响 MariaDB 10.5。

演示:https ://dbfiddle.uk/?rdbms=mariadb_10.5&fiddle=867204670347fa29e40bd5eb510c6956

解决方法是先删除该列所属的 UNIQUE KEY mystage,然后再删除该列。

alter table my_transitions drop key unique_stage_combination, drop column mystage;

PS:我在 MySQL 8.0 上对此进行了测试,它不需要解决方法。它确实删除了该列,但它只在一个列上留下了一个 UNIQUE KEY 列mystage1,这可能不是您想要的。

于 2021-04-05T00:23:54.963 回答