Skip to content

MySQL: Specified key was too long on AbpResourcePermissionGrants unique index (max key length is 3072 bytes) #25492

@Keay5

Description

@Keay5

Is there an existing issue for this?

  • I have searched the existing issues

Description

Description

When creating a new ABP 10.4.0 monolith application with MySQL default configuration, running the initial EF Core migration fails with the following error:

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

This issue blocks all new ABP MySQL projects from running initial migrations by default.

ABP Version

10.4.0

Database Provider

MySQL 8.0+ (InnoDB)

Problem Details

The migration fails when creating the unique index on the AbpResourcePermissionGrants table:

CREATE UNIQUE INDEX `IX_AbpResourcePermissionGrants_TenantId_Name_ResourceName_ResourceKey_ProviderName_ProviderKey`
ON `AbpResourcePermissionGrants` (
    `TenantId`,
    `Name`,
    `ResourceName`,
    `ResourceKey`,
    `ProviderName`,
    `ProviderKey`
);

This is a 6-column composite unique index

With ABP's default utf8mb43072 bytes

Reproduction Steps

  1. Create a new ABP 10.4.0 monolith solution:

    abp new MonoOnAbp -u angular -dbms MySQL -m none --theme leptonx-lite -csf -scp --connection-string "Server=localhost;Port=3306;Database=MonoOnAbp;Uid=root;Pwd=123456;"
    
  2. Set up a valid MySQL connection string

  3. Run:

    dotnet ef migrations add Initial
    dotnet ef database update
    
  4. Migration fails immediately.

Workaround / Fix I Used

I fixed it by reducing the max length of 3 long string fields in OnModelCreating in MonoOnAbpDbContext.cs:

protected override void OnModelCreating(ModelBuilder builder)
{
    base.OnModelCreating(builder);

    builder.ConfigurePermissionManagement();

    // FIX: MySQL index too long issue
    builder.Entity<ResourcePermissionGrant>(e =>
    {
        e.Property(x => x.Name).HasMaxLength(128);
        e.Property(x => x.ResourceName).HasMaxLength(128);
        e.Property(x => x.ResourceKey).HasMaxLength(128);
    });
}

This reduces index size so it fits within the 3072 bytes limit under utf8mb4.

Sample Repository

I have published a complete minimal reproduction repo here:

https://github.com/Keay5/abp-monolith-sample

Expected Behavior

ABP 10.4.0 should generate MySQL-compatible indexes by default.

Actual Behavior

All new MySQL projects fail on first run.

Reproduction Steps

No response

Expected behavior

No response

Actual behavior

No response

Regression?

No response

Known Workarounds

No response

Version

10.4.0

User Interface

Common (Default)

Database Provider

EF Core (Default)

Tiered or separate authentication server

None (Default)

Operation System

Windows (Default)

Other information

No response

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions