{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs#L1224-L1260","documentation":"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.","triggerScenarios":"Configuring `.HasComputedColumnSql(\"\")` and running `EnsureCreated`/`Migrate`/scaffolding, or constructing a column operation whose ComputedColumnSql is set to an empty string.","commonSituations":"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.","solutions":["Provide a real computed expression: `.HasComputedColumnSql(\"[A] + [B]\")`.","If the column is not actually computed, drop the `.HasComputedColumnSql(...)` call.","Guard any generated/fluent code so a non-empty expression is always supplied for computed columns."],"exampleFix":"// before\nmodelBuilder.Entity<Foo>().Property(x => x.Total).HasComputedColumnSql(\"\");\n// after\nmodelBuilder.Entity<Foo>().Property(x => x.Total).HasComputedColumnSql(\"[A] + [B]\");","handlingStrategy":"validation","validationCode":"var sql = GetComputedColumnSql();\nif (sql is { Length: 0 }) throw new ArgumentException(\"ComputedColumnSql must be non-empty or null.\");\nif (sql is not null) builder.HasComputedColumnSql(sql);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always supply a non-empty expression for computed columns.","If the column is not computed, remove the `HasComputedColumnSql` call."],"tags":["efcore","migrations","columns","computed-column","model-differ","relational"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}