Migration 059 failed

Hi!

While upgrade metabase from v57 to v59 we got the following migration issue;

2026-03-25T21:03:47.9916361Z 2026-03-25 21:03:47,977 ERROR liquibase.changelog :: ChangeSet migrations/059_update_migrations.yaml::v59.2026-01-31T12:00:52::crisptrutski encountered an exception.
2026-03-25T21:03:47.9916817Z liquibase.exception.DatabaseException: (conn=41867) Failed to add the foreign key constraint. Missing unique key for constraint 'fk_workspace_output_ref_id' in the referenced table 'workspace_transform' [Failed SQL: (6125) ALTER TABLE `metabase`.`workspace_output` ADD CONSTRAINT `fk_workspace_output_ref_id` FOREIGN KEY (`workspace_id`, `ref_id`) REFERENCES `metabase`.`workspace_transform` (`workspace_id`, `ref_id`) ON DELETE CASCADE]

Any recommendations on how to solve this issue?

The index for that fk should have been created in migration v59.2026-01-31T12:00:39. Check that the index exists. Also check the log if there was an exception, or if that one got marked MARK_RAN due to a precondition failure.

If it’s not there you could create it using this command, but then we have to figure out why it isn’t there and if anything else is missing.

CREATE UNIQUE INDEX idx_workspace_transform_workspace_global_unique ON workspace_transform (workspace_id, global_id)

You can use this MySQL command to view the indexes on the workspace_transform table:

SHOW INDEXES ON TABLE workspace_transform;

The output from an app database for v59.4 that the migrations ran successfully on (sorry, wide):

+---------------------+------------+-------------------------------------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| Table               | Non_unique | Key_name                                        | Seq_in_index | Column_name   | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression |
+---------------------+------------+-------------------------------------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| workspace_transform |          0 | PRIMARY                                         |            1 | workspace_id  | A         |           0 |     NULL |   NULL |      | BTREE      |         |               | YES     | NULL       |
| workspace_transform |          0 | PRIMARY                                         |            2 | ref_id        | A         |           0 |     NULL |   NULL |      | BTREE      |         |               | YES     | NULL       |
| workspace_transform |          0 | entity_id                                       |            1 | entity_id     | A         |           0 |     NULL |   NULL | YES  | BTREE      |         |               | YES     | NULL       |
| workspace_transform |          0 | idx_workspace_transform_workspace_global_unique |            1 | workspace_id  | A         |           0 |     NULL |   NULL |      | BTREE      |         |               | YES     | NULL       |
| workspace_transform |          0 | idx_workspace_transform_workspace_global_unique |            2 | global_id     | A         |           0 |     NULL |   NULL | YES  | BTREE      |         |               | YES     | NULL       |
| workspace_transform |          1 | idx_workspace_transform_workspace_id            |            1 | workspace_id  | A         |           0 |     NULL |   NULL |      | BTREE      |         |               | YES     | NULL       |
| workspace_transform |          1 | idx_workspace_transform_global_id               |            1 | global_id     | A         |           0 |     NULL |   NULL | YES  | BTREE      |         |               | YES     | NULL       |
| workspace_transform |          1 | idx_workspace_transform_collection_id           |            1 | collection_id | A         |           0 |     NULL |   NULL | YES  | BTREE      |         |               | YES     | NULL       |
| workspace_transform |          1 | idx_workspace_transform_creator_id              |            1 | creator_id    | A         |           0 |     NULL |   NULL | YES  | BTREE      |         |               | YES     | NULL       |
+---------------------+------------+-------------------------------------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+

Thanks for helping out.
This index was existing, so that wasn’t the problem.

After some debugging / looking at the changelogs etc. We figured out that we had an existing primary key in the table workspace_transform.

MySQL 8.0+ is automatically creating a PK with a invisible column, if there isn’t one existing (at least for us when hosted in azure).

So we had to executed:
ALTER TABLE workspace_transform
DROP COLUMN my_row_id,
ADD CONSTRAINT pk_workspace_transform PRIMARY KEY (workspace_id, ref_id);

That seems to solve the problem - v59 is now running :slight_smile:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.

Thanks for the update. Noted for the future that its important to know if the instance is an Azure MySQL instance as there is some magic at work.