{"record":{"id":"dba4d015e49389b5","repo":"dotnet/efcore","slug":"the-default-value-sql-has-not-been-specified-for-t","errorCode":null,"errorMessage":"The default value SQL has not been specified for the column '{table}.{column}'. Specify the SQL before using Entity Framework to create the database schema.","messagePattern":"The default value 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":1234,"sourceCode":"    private void Initialize(\n        ColumnOperation columnOperation,\n        IColumn column,\n        RelationalTypeMapping typeMapping,\n        bool isNullable,\n        IEnumerable<IAnnotation> migrationsAnnotations,\n        bool inline = false)\n    {\n        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();","sourceCodeStart":1216,"sourceCodeEnd":1252,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs#L1216-L1252","documentation":"A column flagged as having a default-value SQL expression must carry a non-empty expression. Initialize throws when DefaultValueSql is the empty string, because the schema-generation pipeline cannot emit DEFAULT '' (empty) for a column that claims a default.","triggerScenarios":"A column whose DefaultValueSql is set to string.Empty during migration diffing; typically from .HasDefaultValueSql(\"\") or a convention/scaffolding path that assigns an empty string instead of null.","commonSituations":"Calling .HasDefaultValueSql(string.Empty) or wiring the value from a config/attribute that yields empty; scaffolding bugs producing empty SQL; conditional builder code that sets the SQL conditionally to empty.","solutions":["Pass a real SQL expression to HasDefaultValueSql(\"GETUTCDATE()\").","If no default SQL is intended, remove the call rather than passing empty.","Coerce empty strings to null before assigning DefaultValueSql.","Audit migration scaffolding output for empty default-SQL fragments."],"exampleFix":"// before\nbuilder.Entity<Order>()\n    .Property(o => o.CreatedAt)\n    .HasDefaultValueSql(\"\"); // throws\n\n// after\nbuilder.Entity<Order>()\n    .Property(o => o.CreatedAt)\n    .HasDefaultValueSql(\"GETUTCDATE()\");","handlingStrategy":"validation","validationCode":"// Coerce empty to null, or require a real expression.\nif (!string.IsNullOrEmpty(defaultValueSql))\n{\n    builder.HasDefaultValueSql(defaultValueSql);\n}","typeGuard":"static bool IsValidDefaultValueSql(string? sql)\n    => string.IsNullOrEmpty(sql) || sql.Trim().Length > 0;","tryCatchPattern":null,"preventionTips":["Never pass string.Empty to HasDefaultValueSql.","Sanitize config-driven SQL strings to null when empty.","Inspect scaffolded migrations for empty default-SQL fragments."],"tags":["ef-core","migrations","columns","default-value-sql","configuration"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}