elsa-workflows / elsa-workflows/elsa-core

MySQL runtime migration 20251204150235_V3_6 fails with "Specified key was too long" on utf8mb4

Open
#7,441 0 comments 0 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
7.9k
Forks
1.5k
Avg merge
15h 22m
Merged PRs (30d)
114

Description

## Description

`Elsa.Persistence.EFCore.MySql` runtime migration `20251204150235_V3_6` fails on MySQL with `utf8mb4` when creating the unique index on the `Triggers` table.

Error message:

MySqlConnector.MySqlException: Specified key was too long; max key length is 3072 bytes

The failing SQL is:

CREATE UNIQUE INDEX `IX_StoredTrigger_Unique_WorkflowDefinitionId_Hash_ActivityId_Ten`
ON `Triggers` (`WorkflowDefinitionId`, `Hash`, `ActivityId`, `TenantId`);

It looks like this index can exceed MySQL InnoDB's maximum index key length when the involved columns are `varchar(255)` using `utf8mb4`.

## Steps to Reproduce

1. Create an empty MySQL database using `utf8mb4`.

CREATE DATABASE Test
CHARACTER SET utf8mb4
COLLATE utf8mb4_0900_ai_ci;

2. Create a minimal .NET 8 console app.

3. Small correction for the reproduction steps: step 3 should include these packages:

- Elsa 3.6.1
- Elsa.Persistence.EFCore.MySql 3.6.1
- Microsoft.Extensions.Hosting 9.0.13

4. Register Elsa workflow management and runtime persistence with MySQL and enable migrations:
```charp
using Elsa.Extensions;
using Elsa.Persistence.EFCore.Extensions;
using Elsa.Persistence.EFCore.Modules.Management;
using Elsa.Persistence.EFCore.Modules.Runtime;
using Microsoft.Extensions.Hosting;

const string connectionString =
"Server=XXX;Port=XXX;Database=Test;User ID=XXX;Password=XXX;Allow User Variables=True;Connection Timeout=5";

var builder = Host.CreateApplicationBuilder(args);

builder.Services.AddElsa(elsa =>
{
elsa.UseWorkflowManagement(management =>
management.UseEntityFrameworkCore(ef =>
{
ef.UseMySql(connectionString);
ef.RunMigrations = true;
}));

elsa.UseWorkflowRuntime(runtime =>
runtime.UseEntityFrameworkCore(ef =>
{
ef.UseMySql(connectionString);
ef.RunMigrations = true;
}));
});

using var host = builder.Build();
await host.StartAsync();
await host.StopAsync();
```
5. Run the application.

Reproduction rate: every time on a clean MySQL 8.1.0 database using `utf8mb4`.

## Expected Behavior

The Elsa MySQL runtime migrations should complete successfully.

## Actual Behavior

The workflow management migrations complete, but the runtime migration `20251204150235_V3_6` fails when creating this index:

CREATE UNIQUE INDEX `IX_StoredTrigger_Unique_WorkflowDefinitionId_Hash_ActivityId_Ten`
ON `Triggers` (`WorkflowDefinitionId`, `Hash`, `ActivityId`, `TenantId`);

The migration remains pending, so the same error happens again on the next startup.

## Screenshots

Not applicable.

## Environment

- Elsa Package Version:
- `Elsa` 3.6.1
- `Elsa.Persistence.EFCore.MySql` 3.6.1
- Database:
- MySQL 8.1.0
- Database charset: `utf8mb4`
- Database collation: `utf8mb4_0900_ai_ci`
- Server charset: `utf8mb4`
- Server collation: `utf8mb4_0900_ai_ci`
- Operating System:
- Windows 10
- Target Framework:
- .NET 8

## Log Output

Applying migration '20251204150235_V3_6'.

ALTER TABLE `Triggers` MODIFY COLUMN `ActivityId` varchar(255) CHARACTER SET utf8mb4 NOT NULL;

CREATE UNIQUE INDEX `IX_StoredTrigger_Unique_WorkflowDefinitionId_Hash_ActivityId_Ten`
ON `Triggers` (`WorkflowDefinitionId`, `Hash`, `ActivityId`, `TenantId`);

MySqlConnector.MySqlException (0x80004005): Specified key was too long; max key length is 3072 bytes

## Troubleshooting Attempts

I reproduced this with a minimal console application using the official Elsa registration path and `ef.RunMigrations = true`.

I also tried creating a separate database using `utf8mb3`, but the migration still uses `utf8mb4` explicitly in the generated DDL.

I checked older package lines and noticed that `Elsa.EntityFrameworkCore.MySql` 3.5.3 does not appear to include this specific runtime migration/index. The issue seems related to the `20251204150235_V3_6` migration introduced in the 3.6.x line.

## Additional Context

This appears related to MySQL InnoDB index length limits with `utf8mb4`. The index includes multiple string columns, each mapped as `varchar(255)` / `utf8mb4`.

The failing migration seems to have been introduced to include `TenantId` in the stored trigger unique index.

## Related Issues

None found.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.