{"record":{"id":"d35c6fc69d0e7755","repo":"dotnet/efcore","slug":"the-default-value-has-not-been-specified-for-the-c","errorCode":null,"errorMessage":"The default value has not been specified for the column '{table}.{column}'. Specify a value before using Entity Framework to create the database schema.","messagePattern":"The default value has not been specified for the column '(.+?)\\.(.+?)'\\. Specify a value 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":1226,"sourceCode":"        };\n        operation.AddAnnotations(MigrationsAnnotationProvider.ForRemove(source));\n\n        diffContext.AddDrop(source, operation);\n\n        yield return operation;\n    }\n\n    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,","sourceCodeStart":1208,"sourceCodeEnd":1244,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs#L1208-L1244","documentation":"Thrown by MigrationsModelDiffer.Initialize when a column's `DefaultValue` equals `DBNull.Value`, meaning the model says a default value should exist but none was supplied. This breaks `EnsureCreated`/migration scaffolding because the column would be created with no default to write for non-nullable rows.","triggerScenarios":"Configuring a column with `.HasDefaultValue()` (no argument) but no value/database-side default, then calling `EnsureCreated`, `Migrate`, or scaffolding migrations. Also reached when a non-nullable column maps to a store column that needs an explicit default that was never provided.","commonSituations":"Calling `.HasDefaultValue()` expecting it to infer a value; mixing computed/default annotations manually; building column operations in custom differ code; provider/version upgrade that changed default-value semantics.","solutions":["Provide an explicit default value: `.HasDefaultValue(0)` / `.HasDefaultValueSql(\"0\")`.","If the column should be nullable, configure `.IsRequired(false)` so no default is needed.","If a database-generated default exists, use `.HasDefaultValueSql(\"...\")` to point at it.","Remove the stray `.HasDefaultValue()` call if no default is intended."],"exampleFix":"// before\nmodelBuilder.Entity<Foo>().Property(x => x.Count).HasDefaultValue();\n// after\nmodelBuilder.Entity<Foo>().Property(x => x.Count).HasDefaultValue(0);","handlingStrategy":"validation","validationCode":"// In OnModelCreating, ensure every HasDefaultValue() column has a real value or is nullable.\nforeach (var prop in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetProperties()))\n{\n    if (!prop.IsNullable\n        && prop.GetDefaultValue() == DBNull.Value\n        && string.IsNullOrEmpty(prop.GetDefaultValueSql())\n        && prop.GetComputedColumnSql() is null)\n    {\n        // decide: set a value, a DefaultValueSql, or make the property nullable.\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass an explicit value or SQL to `.HasDefaultValue`/`.HasDefaultValueSql`.","Prefer `.HasDefaultValueSql(\"...\")` when the default is database-side.","Make columns nullable if no default is intended."],"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"}