dotnet/efcore · error · InvalidOperationException
' . ' and ' . ' are both mapped to column ' ' in ' ', but…
Error message
'{entityType1}.{property1}' and '{entityType2}.{property2}' are both mapped to column '{columnName}' in '{table}', but are configured to use different column orders ('{columnOrder1}' and '{columnOrder2}'). What it means
Two properties sharing a column declare different explicit column orders via HasColumnOrder. Since they share one physical column they must agree on its position; a mismatch would generate contradictory column-ordering in migrations. Compared as plain int? inequality (null = unspecified, treated as equal).
Solutions
- Pass the same integer to HasColumnOrder on both properties.
- Remove HasColumnOrder from one side so both leave it unspecified (null), letting conventions order them.
- If the orders must differ, remap one property to its own column.
Example fix
// before modelBuilder.Entity<User>().Property(u => u.Email).HasColumnOrder(3); modelBuilder.Entity<UserSettings>().Property(s => s.Email).HasColumnOrder(5); // shared column // after modelBuilder.Entity<User>().Property(u => u.Email).HasColumnOrder(3); modelBuilder.Entity<UserSettings>().Property(s => s.Email).HasColumnOrder(3);
Defensive patterns
Strategy: validation
Validate before calling
foreach (var (col, props) in sharedColumnGroups)
{
var orders = props.Select(p => p.GetColumnOrder(storeObject)).Distinct().ToList();
if (orders.Count > 1)
Console.WriteLine($"Column {col} has conflicting orders: {string.Join(", ", orders)}");
} Try / catch
try { _ = db.Model; } catch (InvalidOperationException ex) when (ex.Message.Contains("different column orders")) { // align HasColumnOrder on both properties, or remove it } Prevention
- Prefer leaving column order unset unless a specific schema ordering is required.
- If set, define it in one place and reuse on all entities sharing the column.
- Smoke-test the model at startup.
When it happens
Trigger: ValidateCompatible() reads property.GetColumnOrder(storeObject) and duplicateProperty.GetColumnOrder(storeObject); if the nullable ints differ it throws. Happens when both halves of a table-split call HasColumnOrder with different ordinals.
Common situations: Refactor that re-numbered columns on one entity but not its split partner; merging two separately-maintained models; scaffolded model edited to add column ordering on only one entity.
Related errors
- ' . ' and ' . ' are both mapped to column ' ' in ' ', but…
- ' . ' and ' . ' are both mapped to column ' ' in ' ', but…
- ' . ' and ' . ' are both mapped to column ' ' in ' ', but…
- ' . ' and ' . ' are both mapped to column ' ' in ' ', but…
- ' . ' and ' . ' are both mapped to column ' ' in ' ', but…
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/0300a04333b10337.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs:1780
if (!currentCollation.Equals(previousCollation, StringComparison.Ordinal))
{
throw new InvalidOperationException(
RelationalStrings.DuplicateColumnNameCollationMismatch(
duplicateProperty.DeclaringType.DisplayName(),
duplicateProperty.Name,
property.DeclaringType.DisplayName(),
property.Name,
columnName,
storeObject.DisplayName(),
previousCollation,
currentCollation));
}
var currentColumnOrder = property.GetColumnOrder(storeObject);
var previousColumnOrder = duplicateProperty.GetColumnOrder(storeObject);
if (currentColumnOrder != previousColumnOrder)
{
throw new InvalidOperationException(
RelationalStrings.DuplicateColumnNameOrderMismatch(
duplicateProperty.DeclaringType.DisplayName(),
duplicateProperty.Name,
property.DeclaringType.DisplayName(),
property.Name,
columnName,
storeObject.DisplayName(),
previousColumnOrder,
currentColumnOrder));
}
}
/// <summary>
/// Returns the object that is used as the default value for the column the property is mapped to.
/// </summary>
/// <param name="property">The property to get the default value for.</param>
/// <param name="storeObject">The identifier of the store object.</param>
/// <returns>The object that is used as the default value for the column the property is mapped to.</returns>View on GitHub (pinned to 3a2006ef56)