{"record":{"id":"951f414b2cd78089","repo":"dotnet/efcore","slug":"conflictingconfiguration-cannot-be-set-for-p","errorCode":null,"errorMessage":"'{conflictingConfiguration}' cannot be set for '{property}' at the same time as '{existingConfiguration}'. Remove one of these configurations.","messagePattern":"'(.+?)' cannot be set for '(.+?)' at the same time as '(.+?)'\\. Remove one of these configurations\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Metadata/Conventions/StoreGenerationConvention.cs","lineNumber":132,"sourceCode":"                Validate(declaredProperty, declaringTable);\n            }\n        }\n    }\n\n    /// <summary>\n    ///     Throws if there is conflicting store generation configuration for this property.\n    /// </summary>\n    /// <param name=\"property\">The property to check.</param>\n    /// <param name=\"storeObject\">The identifier of the store object.</param>\n    protected virtual void Validate(\n        IConventionProperty property,\n        in StoreObjectIdentifier storeObject)\n    {\n        if (property.TryGetDefaultValue(storeObject, out _))\n        {\n            if (property.GetDefaultValueSql(storeObject) != null)\n            {\n                throw new InvalidOperationException(\n                    RelationalStrings.ConflictingColumnServerGeneration(\"DefaultValue\", property.Name, \"DefaultValueSql\"));\n            }\n\n            if (property.GetComputedColumnSql(storeObject) != null)\n            {\n                throw new InvalidOperationException(\n                    RelationalStrings.ConflictingColumnServerGeneration(\"DefaultValue\", property.Name, \"ComputedColumnSql\"));\n            }\n        }\n        else if (property.GetDefaultValueSql(storeObject) != null)\n        {\n            if (property.GetComputedColumnSql(storeObject) != null)\n            {\n                throw new InvalidOperationException(\n                    RelationalStrings.ConflictingColumnServerGeneration(\"DefaultValueSql\", property.Name, \"ComputedColumnSql\"));\n            }\n        }\n    }","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Metadata/Conventions/StoreGenerationConvention.cs#L114-L150","documentation":"Thrown by StoreGenerationConvention.Validate (StoreGenerationConvention.cs:128-134) during model finalizing when a property has both a DefaultValue and a DefaultValueSql configured for the same store object. These are mutually exclusive: DefaultValue sets a literal .NET value as the column default, while DefaultValueSql sets a raw SQL expression — only one can be the column's DEFAULT. The convention enforces this at model validation time.","triggerScenarios":"Calling both .HasDefaultValue(someValue) and .HasDefaultValueSql(\"GETDATE()\") on the same property. Also when one is set via data annotation / convention and the other via fluent API. The Validate method checks TryGetDefaultValue first, then if DefaultValueSql is also non-null, throws.","commonSituations":"Chaining configuration calls or merging config from multiple sources where both default value and default SQL are set. Migrating from HasDefaultValue to HasDefaultValueSql without removing the old call. Configuration split across partial OnModelCreating methods.","solutions":["Choose one: use HasDefaultValue(value) for a literal, or HasDefaultValueSql(\"SQL\") for an expression — not both.","Remove the conflicting call by passing null: .HasDefaultValue(null) before setting HasDefaultValueSql.","Search for all configuration of the property across the model to find and remove the duplicate."],"exampleFix":"// before: both default value and default SQL\nmodelBuilder.Entity<Order>()\n    .Property(o => o.CreatedAt)\n    .HasDefaultValue(DateTime.UtcNow)\n    .HasDefaultValueSql(\"GETUTCDATE()\"); // throws\n\n// after: only one\nmodelBuilder.Entity<Order>()\n    .Property(o => o.CreatedAt)\n    .HasDefaultValueSql(\"GETUTCDATE()\");","handlingStrategy":"validation","validationCode":"foreach (var et in modelBuilder.Model.GetEntityTypes())\n{\n    foreach (var prop in et.GetDeclaredProperties())\n    {\n        foreach (var table in prop.GetMappedStoreObjects(StoreObjectType.Table))\n        {\n            if (prop.TryGetDefaultValue(table, out _) && prop.GetDefaultValueSql(table) != null)\n                Console.WriteLine($\"Conflict: {et.DisplayName()}.{prop.Name} has both DefaultValue and DefaultValueSql on {table.Name}.\");\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Centralize property value-generation configuration in one place per property.","Never chain HasDefaultValue().HasDefaultValueSql() — choose one.","Add a model validation test that scans for conflicting store-generation annotations."],"tags":["store-generation","default-value","conflicting-configuration","convention"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}