{"record":{"id":"fed4a1c1eaea0f83","repo":"dotnet/efcore","slug":"a-seed-entity-for-entity-type-entitytype-has-t-fed4a1","errorCode":null,"errorMessage":"A seed entity for entity type '{entityType}' has the same key value as another seed entity mapped to the same table '{table}', but have different values for the column '{column}'. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting values.","messagePattern":"A seed entity for entity type '(.+?)' has the same key value as another seed entity mapped to the same table '(.+?)', but have different values for the column '(.+?)'\\. Consider using 'DbContextOptionsBuilder\\.EnableSensitiveDataLogging' to see the conflicting values\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs","lineNumber":2020,"sourceCode":"\n                    var existingColumnModification = command.ColumnModifications.FirstOrDefault(c => c.ColumnName == column.Name);\n                    if (existingColumnModification != null)\n                    {\n                        if (!Equals(NormalizeSeedValue(existingColumnModification.Value), NormalizeSeedValue(value)))\n                        {\n                            if (sensitiveLoggingEnabled)\n                            {\n                                throw new InvalidOperationException(\n                                    RelationalStrings.ConflictingSeedValuesSensitive(\n                                        entityType.DisplayName(),\n                                        BuildValuesString(key),\n                                        table.SchemaQualifiedName,\n                                        existingColumnModification.ColumnName,\n                                        Convert.ToString(existingColumnModification.Value, CultureInfo.InvariantCulture),\n                                        Convert.ToString(value, CultureInfo.InvariantCulture)));\n                            }\n\n                            throw new InvalidOperationException(\n                                RelationalStrings.ConflictingSeedValues(\n                                    entityType.DisplayName(),\n                                    table.SchemaQualifiedName,\n                                    existingColumnModification.ColumnName));\n                        }\n\n                        continue;\n                    }\n\n                    writeValue = writeValue\n                        && initialState != EntityState.Deleted\n                        && property.GetBeforeSaveBehavior() == PropertySaveBehavior.Save;\n\n                    command.AddColumnModification(\n                        new ColumnModificationParameters(\n                            column, originalValue: value, value, property, columnMapping.TypeMapping,\n                            read: false, write: writeValue,\n                            key: property.IsPrimaryKey(), condition: false,","sourceCodeStart":2002,"sourceCodeEnd":2038,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs#L2002-L2038","documentation":"Non-sensitive variant of the conflicting-seed-values check: same key, same table, but two seed entries disagree on a non-key column. The column name is reported but the values are hidden; turn on EnableSensitiveDataLogging to see them. Same root cause as error 521.","triggerScenarios":"HasData contains two entries with identical keys but a differing value for some mapped column, while sensitive data logging is OFF. Reached during model diffing for migrations or any code that builds seed commands.","commonSituations":"Default state in production where EnableSensitiveDataLogging is (correctly) disabled; copy-paste of seed entries with one field edited; refactor that split one seed source into two without deduplicating.","solutions":["Temporarily enable optionsBuilder.EnableSensitiveDataLogging() to surface the exact key and both values (error 521), then disable it again.","Search HasData blocks for the reported entity type and reconcile the conflicting column.","Ensure only one seed entry exists per key per table.","Regenerate the migration after the fix."],"exampleFix":"// before\nmodelBuilder.Entity<Product>().HasData(\n    new Product { Id = 7, Sku = \"A1\" },\n    new Product { Id = 7, Sku = \"B2\" });\n\n// after\nmodelBuilder.Entity<Product>().HasData(\n    new Product { Id = 7, Sku = \"A1\" });","handlingStrategy":"validation","validationCode":"// Reuse the AssertSeedConsistent helper from 521; run it in a unit test\n// against the model's configured seed data, with sensitive logging OFF in prod.\n[Test] public void Seed_Data_Is_Consistent()\n    => AssertSeedConsistent(_seedCustomers, c => c.Id, c => c.Sku, c => c.Name);","typeGuard":"null","tryCatchPattern":"// In tooling, catch and re-run with sensitive logging for diagnostics\ntry { db.Database.Migrate(); }\ncatch (InvalidOperationException ex)\n    when (ex.Message.Contains(\"same key value\"))\n{\n    using var sensitive = new DbContextOptionsBuilder<Db>()\n        .UseSqlServer(conn).EnableSensitiveDataLogging().Options;\n    using var diag = new Db(sensitive);\n    diag.Database.Migrate(); // surfaces exact values\n    throw;\n}","preventionTips":["Run the model-differ in a test (call db.GetService<IMigrationsModelDiffer>()) before deploy.","Keep seed definitions DRY — one initializer per entity.","Review any PR that touches HasData for duplicate keys or diverging columns."],"tags":["migrations","seeding","data-integrity"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}