Skip to content

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

@ZhangSen1

Description

@ZhangSen1

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:

    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();
  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions