{"record":{"id":"27767ba0d3ad748b","repo":"dotnet/efcore","slug":"the-computed-column-sql-has-not-been-specified-for","errorCode":null,"errorMessage":"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.","messagePattern":"The computed column SQL has not been specified for the column '(.+?)\\.(.+?)'\\. Specify the SQL before using Entity Framework to create the database schema\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs","lineNumber":1242,"sourceCode":"        if (column.DefaultValue == DBNull.Value)\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.DefaultValueUnspecified(\n                    column.Table.SchemaQualifiedName,\n                    column.Name));\n        }\n\n        if (column.DefaultValueSql?.Length == 0)\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.DefaultValueSqlUnspecified(\n                    column.Table.SchemaQualifiedName,\n                    column.Name));\n        }\n\n        if (column.ComputedColumnSql?.Length == 0)\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.ComputedColumnSqlUnspecified(\n                    column.Name,\n                    column.Table.SchemaQualifiedName));\n        }\n\n        var property = column.PropertyMappings.First().Property;\n        var valueConverter = GetValueConverter(property, typeMapping);\n        columnOperation.ClrType\n            = (valueConverter?.ProviderClrType\n                ?? typeMapping.ClrType).UnwrapNullableType();\n\n        column.TryGetDefaultValue(out var defaultValue);\n        columnOperation.DefaultValue = defaultValue\n            ?? (inline || isNullable\n                ? null\n                : typeMapping.GetDefaultProviderValue());\n        columnOperation.DefaultValueSql = column.DefaultValueSql;\n        columnOperation.ColumnType = column.StoreType;","sourceCodeStart":1224,"sourceCodeEnd":1260,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs#L1224-L1260","documentation":"A column flagged as computed must supply its defining SQL. Initialize throws when ComputedColumnSql is the empty string, because EF cannot emit a GENERATED ALWAYS AS clause with no expression.","triggerScenarios":"A column whose ComputedColumnSql is set to string.Empty during migration diffing; from .HasComputedColumnSql(\"\") or scaffolding/attribute code that yields empty.","commonSituations":"Calling .HasComputedColumnSql(string.Empty); wiring the SQL from a config value that resolves empty; scaffolding round-trips that drop the expression; conditional builder code assigning empty.","solutions":["Pass a real expression to HasComputedColumnSql(\"[Qty] * [Price]\").","If the column is not computed, remove the call entirely.","Coerce empty strings to null before assigning ComputedColumnSql.","Verify scaffolder output preserves the expression."],"exampleFix":"// before\nbuilder.Entity<Order>()\n    .Property(o => o.Total)\n    .HasComputedColumnSql(\"\"); // throws\n\n// after\nbuilder.Entity<Order>()\n    .Property(o => o.Total)\n    .HasComputedColumnSql(\"[Qty] * [UnitPrice]\");","handlingStrategy":"validation","validationCode":"if (!string.IsNullOrEmpty(computedColumnSql))\n{\n    builder.HasComputedColumnSql(computedColumnSql);\n}","typeGuard":"static bool IsValidComputedColumnSql(string? sql)\n    => string.IsNullOrEmpty(sql) || sql.Trim().Length > 0;","tryCatchPattern":null,"preventionTips":["Never pass string.Empty to HasComputedColumnSql.","Null-out empty computed SQL before configuring.","Review scaffolder output for missing expressions."],"tags":["ef-core","migrations","columns","computed-column","configuration"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}