dotnet/efcore · error · NotSupportedException

SQL generation for the operation

Error message

SQL generation for the operation '{operation}' is not supported by the current database provider. Database providers must implement the appropriate method in 'MigrationsSqlGenerator' to support this operation.

What it means

Default implementation of Generate(AlterColumnOperation, ...) throws NotSupportedException. AlterColumnOperation is relational but not every provider implements column-alter SQL the same way, so the base class makes the provider opt in. The provider package must override this method to support migrations that alter columns.

Solutions

  1. Upgrade the database provider package to one that implements AlterColumnOperation support.
  2. If you maintain the provider, override Generate(AlterColumnOperation, IModel, MigrationCommandListBuilder).
  3. As a workaround, drop and re-add the column instead of altering it (data loss risk — back up first).

Example fix

// before — provider lacks AlterColumn; migration throws
migrationBuilder.AlterColumn<string>("Email", "Users", maxLength: 200);

// workaround — drop + recreate (provider supports these)
migrationBuilder.DropColumn("Email", "Users");
migrationBuilder.AddColumn<string>("Email", "Users", maxLength: 200);

// proper fix — implement in the provider
class MyProviderSqlGenerator : MigrationsSqlGenerator
{
    protected override void Generate(
        AlterColumnOperation op, IModel? model, MigrationCommandListBuilder b)
    {
        // emit provider-specific ALTER COLUMN ...
    }
}
Defensive patterns

Strategy: validation

Validate before calling

// Detect provider support for AlterColumnOperation before running
var gen = db.GetService<IMigrationsSqlGenerator>().GetType();
bool supportsAlter = gen.GetMethod("Generate",
    BindingFlags.Instance | BindingFlags.NonPublic,
    null, CallingConventions.Any,
    new[] { typeof(AlterColumnOperation), typeof(IModel), typeof(MigrationCommandListBuilder) },
    null)?.DeclaringType != typeof(MigrationsSqlGenerator);

Type guard

null

Prevention

When it happens

Trigger: A migration calls migrationBuilder.AlterColumn<T>(...) and the active provider's MigrationsSqlGenerator did not override the AlterColumn Generate method (rare for shipping providers like SqlServer/Postgres, common for minimal/custom providers or a very old provider version).

Common situations: Using a community/in-progress database provider that has not implemented AlterColumn yet; running migrations generated for one provider against a stub provider in tests; provider package version mismatch after an EF Core upgrade.

Related errors


AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11). Data as JSON: /api/errors/b22ff202a9c7dffe. Report an issue: GitHub.

Appendix: source

Thrown at src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs:310

        EndStatement(builder);
    }

    /// <summary>
    ///     Can be overridden by database providers to build commands for the given <see cref="AlterColumnOperation" />
    ///     by making calls on the given <see cref="MigrationCommandListBuilder" />.
    /// </summary>
    /// <remarks>
    ///     Note that the default implementation of this method throws <see cref="NotSupportedException" />. Providers
    ///     must override if they are to support this kind of operation.
    /// </remarks>
    /// <param name="operation">The operation.</param>
    /// <param name="model">The target model which may be <see langword="null" /> if the operations exist without a model.</param>
    /// <param name="builder">The command builder to use to build the commands.</param>
    protected virtual void Generate(
        AlterColumnOperation operation,
        IModel? model,
        MigrationCommandListBuilder builder)
        => throw new NotSupportedException(RelationalStrings.MigrationSqlGenerationMissing(nameof(AlterColumnOperation)));

    /// <summary>
    ///     Can be overridden by database providers to build commands for the given <see cref="AlterDatabaseOperation" />
    ///     by making calls on the given <see cref="MigrationCommandListBuilder" />.
    /// </summary>
    /// <remarks>
    ///     Note that there is no default implementation of this method. Providers must override if they are to
    ///     support this kind of operation.
    /// </remarks>
    /// <param name="operation">The operation.</param>
    /// <param name="model">The target model which may be <see langword="null" /> if the operations exist without a model.</param>
    /// <param name="builder">The command builder to use to build the commands.</param>
    protected virtual void Generate(
        AlterDatabaseOperation operation,
        IModel? model,
        MigrationCommandListBuilder builder)
    {
    }

View on GitHub (pinned to 3a2006ef56)