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
- Enable `EnableSensitiveDataLogging()` in a dev/staging run to see the conflicting column and values (error 551 message).
- Align the conflicting column values across the colliding seed entries.
- 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
- Turn on `EnableSensitiveDataLogging` during development to expose the conflicting column and values.
- Keep seed values consistent across entries sharing a key on a shared table.
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
- A seed entity for entity type '{entityType}' has the same ke
- A seed entity for entity type '{entityType}' has the same ke
- A seed entity for entity type '{entityType}' has the same ke
- command.EntityState.ToString()
- The default value has not been specified for the column '{ta
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/fed4a1c1eaea0f83.
Report an issue: GitHub.