#1794·atlas

Trying to drop non existing index

Author: elitanCreated Jun 27, 2023Updated Sep 29, 2026

I encountered a problem when working with a Mysql 5.7 schema.

I used the atlas schema inspect command to get the schema.sql file.

Then I made a small change in the schema and tried to apply it but got an error.

I went from this:

sql
CREATE TABLE `clients_has_tag`(
  `tag_id` int NOT NULL,
  `client_id` int NOT NULL,
  `company_id` int NOT NULL,
  PRIMARY KEY (`tag_id`, `client_id`, `company_id`),
  INDEX `fk_clients_has_tag_clients1_idx`(`client_id`),
  INDEX `fk_clients_has_tag_tag1_idx`(`tag_id`, `company_id`),
  UNIQUE INDEX `fk_clients_has_tag_unique_tag`(`tag_id`, `client_id`, `company_id`),
  CONSTRAINT `fk_clients_client_id` FOREIGN KEY (`client_id`) REFERENCES `clients`(`cl_ID`) ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT `fk_clients_has_tag_tag_id` FOREIGN KEY (`tag_id`, `company_id`) REFERENCES `tag`(`id`, `company_id`) ON UPDATE NO ACTION ON DELETE NO ACTION) CHARSET latin1 COLLATE latin1_swedish_ci;

to this:

sql
CREATE TABLE `clients_has_tag`(
  `tag_id` int NOT NULL,
  `client_id` int NOT NULL,
  `company_id` int NOT NULL,
  PRIMARY KEY (`tag_id`, `client_id`, `company_id`),
  INDEX `fk_clients_has_tag_clients1_idx`(`client_id`),
  INDEX `fk_clients_has_tag_tag1_idx`(`tag_id`, `company_id`),
  UNIQUE INDEX `fk_clients_has_tag_unique_tag`(`tag_id`, `client_id`, `company_id`),
  CONSTRAINT `fk_clients_client_id` FOREIGN KEY (`client_id`) REFERENCES `clients`(`cl_ID`) ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT `fk_clients_has_tag_tag_id` FOREIGN KEY (`tag_id`) REFERENCES `tag`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION) CHARSET latin1 COLLATE latin1_swedish_ci;

I'm only changing the last FK to only include tag_id instead of both tag_id, and company_id.

Here's the output of the apply command:

-- Planned Changes:
-- Modify "clients_has_tag" table
ALTER TABLE `clients_has_tag` DROP FOREIGN KEY `fk_clients_has_tag_tag_id`, DROP INDEX `fk_clients_has_tag_tag_id`;
-- Modify "clients_has_tag" table
ALTER TABLE `clients_has_tag` ADD CONSTRAINT `fk_clients_has_tag_tag_id` FOREIGN KEY (`tag_id`) REFERENCES `tag` (`id`) ON UPDATE NO ACTION ON DELETE NO ACTION;

✔ Apply
Error: modify "clients_has_tag" table: Error 1091 (42000): Can't DROP 'fk_clients_has_tag_tag_id'; check that column/key exists

The problem is that Atlas tries to drop both an FK and INDEX named fk_clients_has_tag_tag_id. The FK exists, but not the INDEX.

Running only:

sql
ALTER TABLE `clients_has_tag` DROP INDEX `fk_clients_has_tag_tag_id`;

... results in:

Query 1 ERROR: Can't DROP 'fk_clients_has_tag_tag_id'; check that column/key exists