{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs#L1216-L1252","documentation":"Thrown by MigrationsModelDiffer.Initialize when a column's `DefaultValueSql` is an empty string (length 0). An empty SQL fragment is treated as 'unspecified but required', so EF refuses to generate a column definition without a real SQL expression.","triggerScenarios":"Configuring `.HasDefaultValueSql(\"\")` (empty string) and then running `EnsureCreated`/`Migrate`/scaffolding, or building a column operation that sets DefaultValueSql to \"\" in custom differ code.","commonSituations":"Passing an empty/default string into `.HasDefaultValueSql(someVariable)` where the variable is empty; refactoring that leaves `string.Empty` in fluent config; template-generated migration code with blank SQL.","solutions":["Pass a real SQL expression: `.HasDefaultValueSql(\"GETUTCDATE()\")`.","If no SQL default is wanted, remove the `.HasDefaultValueSql(...)` call entirely (use `null`).","Validate the SQL string is non-empty before assigning it in generated differ code."],"exampleFix":"// before\nmodelBuilder.Entity<Foo>().Property(x => x.Created).HasDefaultValueSql(\"\");\n// after\nmodelBuilder.Entity<Foo>().Property(x => x.Created).HasDefaultValueSql(\"GETUTCDATE()\");","handlingStrategy":"validation","validationCode":"// Reject empty default-value SQL before applying config.\nvar sql = GetDefaultValueSql(); // your source\nif (sql is { Length: 0 }) throw new ArgumentException(\"DefaultValueSql must be non-empty or null.\");\nif (sql is not null) builder.HasDefaultValueSql(sql);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass a real SQL expression to `HasDefaultValueSql`, or omit the call entirely.","Validate generated/fluent SQL strings are non-empty before assignment."],"tags":["efcore","migrations","columns","default-value","model-differ","relational"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}