{"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/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs#L1208-L1244","documentation":"When generating column DDL, EF requires a concrete default if a default was requested. Initialize throws when column.DefaultValue equals DBNull.Value, which marks an explicitly-requested-but-unspecified default. The column was flagged as having a default but no value was supplied.","triggerScenarios":"A column whose DefaultValue is set to DBNull.Value (rather than left null) during migration diffing; usually a property configured with HasDefaultValue() but no argument, or a value-converter scenario that nulls the default.","commonSituations":"Calling .HasDefaultValue() with no value on a non-nullable property; scaffolding that emits an empty default; migrations referencing a property whose default was never set; conventions that mark DefaultValue as requested without supplying it.","solutions":["Supply an explicit value to HasDefaultValue(value) or use HasDefaultValueSql(sql) / HasComputedColumnSql(sql).","Remove the HasDefaultValue() call entirely if no default is intended.","If a value converter is involved, ensure the provider-side default is set.","Inspect the column mapping in the migration to see which property produced the DBNull default."],"exampleFix":"// before\nbuilder.Entity<Order>()\n    .Property(o => o.Status)\n    .HasDefaultValue(); // throws on migration\n\n// after\nbuilder.Entity<Order>()\n    .Property(o => o.Status)\n    .HasDefaultValue(\"Pending\");","handlingStrategy":"validation","validationCode":"// In model configuration, never call HasDefaultValue() without a value\n// unless a value-converter/SQL default is intended elsewhere.\n// Guard:\nif (defaultValueRequested && defaultValue is DBNull or null)\n{\n    throw new InvalidOperationException(\"Supply a value or remove HasDefaultValue().\");\n}","typeGuard":"static bool HasValidDefault(object? defaultValue, string? defaultValueSql)\n    => defaultValue is not DBNull || !string.IsNullOrEmpty(defaultValueSql);","tryCatchPattern":null,"preventionTips":["Always pass a concrete value to HasDefaultValue(value).","Prefer HasDefaultValueSql/HasComputedColumnSql for SQL-backed defaults.","Add a model-validation test that asserts no column has DefaultValue == DBNull.Value."],"tags":["ef-core","migrations","columns","default-value","configuration"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}