dotnet/efcore · error · InvalidOperationException

A seed entity for entity type '{entityType}' has the same ke

Error message

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.

What it means

Non-sensitive variant of error 551: two seed entities share a key on a shared table but assign different values to the same column, and because sensitive logging is disabled the values are omitted and the message suggests enabling `EnableSensitiveDataLogging`.

Source

Thrown at src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs:2020

                    var existingColumnModification = command.ColumnModifications.FirstOrDefault(c => c.ColumnName == column.Name);
                    if (existingColumnModification != null)
                    {
                        if (!Equals(NormalizeSeedValue(existingColumnModification.Value), NormalizeSeedValue(value)))
                        {
                            if (sensitiveLoggingEnabled)
                            {
                                throw new InvalidOperationException(
                                    RelationalStrings.ConflictingSeedValuesSensitive(
                                        entityType.DisplayName(),
                                        BuildValuesString(key),
                                        table.SchemaQualifiedName,
                                        existingColumnModification.ColumnName,
                                        Convert.ToString(existingColumnModification.Value, CultureInfo.InvariantCulture),
                                        Convert.ToString(value, CultureInfo.InvariantCulture)));
                            }

                            throw new InvalidOperationException(
                                RelationalStrings.ConflictingSeedValues(
                                    entityType.DisplayName(),
                                    table.SchemaQualifiedName,
                                    existingColumnModification.ColumnName));
                        }

                        continue;
                    }

                    writeValue = writeValue
                        && initialState != EntityState.Deleted
                        && property.GetBeforeSaveBehavior() == PropertySaveBehavior.Save;

                    command.AddColumnModification(
                        new ColumnModificationParameters(
                            column, originalValue: value, value, property, columnMapping.TypeMapping,
                            read: false, write: writeValue,
                            key: property.IsPrimaryKey(), condition: false,

View on GitHub (pinned to dbf9771522)

Solutions

  1. Enable `EnableSensitiveDataLogging()` in a dev/staging run to see the conflicting column and values (error 551 message).
  2. Align the conflicting column values across the colliding seed entries.
  3. Consolidate the seed entries or change keys so they no longer collide.

Example fix

// before
optionsBuilder.UseSqlServer(cs);
// diagnose
optionsBuilder.UseSqlServer(cs).EnableSensitiveDataLogging();
// fix: align the conflicting column value across shared-key seed rows
Defensive patterns

Strategy: validation

Validate before calling

// Enable sensitive logging in dev to see which column/value conflicts.
if (env.IsDevelopment()) optionsBuilder.EnableSensitiveDataLogging();
// Then align the conflicting column values (see 551 validation).

Prevention

When it happens

Trigger: Same as 551 but with `EnableSensitiveDataLogging()` off: colliding seed rows with conflicting column values across shared-table entity types.

Common situations: Production logging config; inheritance hierarchies seeding shared columns inconsistently; merged seed data from multiple config sources.

Related errors


AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06). Data as JSON: /api/errors/fed4a1c1eaea0f83. Report an issue: GitHub.