dotnet/efcore · error · InvalidOperationException

The computed column SQL has not been specified for the colum

Error message

The computed column SQL has not been specified for the column '{table}.{column}'. Specify the SQL before using Entity Framework to create the database schema.

What it means

Thrown by MigrationsModelDiffer.Initialize when a column's `ComputedColumnSql` is an empty string. A computed column requires a non-empty SQL expression; an empty string means 'marked computed but no formula supplied', so EF cannot generate the column definition.

Source

Thrown at src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs:1242

        if (column.DefaultValue == DBNull.Value)
        {
            throw new InvalidOperationException(
                RelationalStrings.DefaultValueUnspecified(
                    column.Table.SchemaQualifiedName,
                    column.Name));
        }

        if (column.DefaultValueSql?.Length == 0)
        {
            throw new InvalidOperationException(
                RelationalStrings.DefaultValueSqlUnspecified(
                    column.Table.SchemaQualifiedName,
                    column.Name));
        }

        if (column.ComputedColumnSql?.Length == 0)
        {
            throw new InvalidOperationException(
                RelationalStrings.ComputedColumnSqlUnspecified(
                    column.Name,
                    column.Table.SchemaQualifiedName));
        }

        var property = column.PropertyMappings.First().Property;
        var valueConverter = GetValueConverter(property, typeMapping);
        columnOperation.ClrType
            = (valueConverter?.ProviderClrType
                ?? typeMapping.ClrType).UnwrapNullableType();

        column.TryGetDefaultValue(out var defaultValue);
        columnOperation.DefaultValue = defaultValue
            ?? (inline || isNullable
                ? null
                : typeMapping.GetDefaultProviderValue());
        columnOperation.DefaultValueSql = column.DefaultValueSql;
        columnOperation.ColumnType = column.StoreType;

View on GitHub (pinned to dbf9771522)

Solutions

  1. Provide a real computed expression: `.HasComputedColumnSql("[A] + [B]")`.
  2. If the column is not actually computed, drop the `.HasComputedColumnSql(...)` call.
  3. Guard any generated/fluent code so a non-empty expression is always supplied for computed columns.

Example fix

// before
modelBuilder.Entity<Foo>().Property(x => x.Total).HasComputedColumnSql("");
// after
modelBuilder.Entity<Foo>().Property(x => x.Total).HasComputedColumnSql("[A] + [B]");
Defensive patterns

Strategy: validation

Validate before calling

var sql = GetComputedColumnSql();
if (sql is { Length: 0 }) throw new ArgumentException("ComputedColumnSql must be non-empty or null.");
if (sql is not null) builder.HasComputedColumnSql(sql);

Prevention

When it happens

Trigger: Configuring `.HasComputedColumnSql("")` and running `EnsureCreated`/`Migrate`/scaffolding, or constructing a column operation whose ComputedColumnSql is set to an empty string.

Common situations: Passing a variable/string into `.HasComputedColumnSql(expr)` where `expr` is empty; generated migration templates leaving blank computed SQL; refactoring that nulls out the expression incorrectly.

Related errors


AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06). Data as JSON: /api/errors/27767ba0d3ad748b. Report an issue: GitHub.