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 have different fixed length configuration.

What it means

Two properties sharing a column have conflicting IsFixedLength settings. Fixed length changes the store type (e.g. nchar vs nvarchar), so EF rejects the ambiguity rather than silently choosing one. Common on SQL Server where fixed-length columns pad with spaces.

Solutions

  1. Apply the same IsFixedLength() setting to both properties.
  2. Remove IsFixedLength() from one side so both fall back to the default (false).
  3. Remap one property to a different column if fixed vs variable is genuinely required.

Example fix

// before
modelBuilder.Entity<Credential>().Property(c => c.Token).IsFixedLength();
modelBuilder.Entity<CredentialMeta>().Property(m => m.Token); // shared column, default = not fixed

// after
modelBuilder.Entity<Credential>().Property(c => c.Token).IsFixedLength();
modelBuilder.Entity<CredentialMeta>().Property(m => m.Token).IsFixedLength();
Defensive patterns

Strategy: validation

Validate before calling

foreach (var (col, props) in sharedColumnGroups)
{
    var flags = props.Select(p => p.IsFixedLength(storeObject)).Distinct().ToList();
    if (flags.Count > 1)
        Console.WriteLine($"Column {col} has conflicting fixed-length settings");
}

Try / catch

try { _ = db.Model; } catch (InvalidOperationException ex) when (ex.Message.Contains("different fixed length configuration")) { // align IsFixedLength on both properties }

Prevention

When it happens

Trigger: ValidateCompatible() checks property.IsFixedLength(storeObject) != duplicateProperty.IsFixedLength(storeObject) for a duplicate column. One property calls IsFixedLength() and the other does not (or sets the opposite).

Common situations: Table splitting where one partner sets IsFixedLength() for legacy compatibility; scaffolded model edited inconsistently; cross-provider migrations where fixed length was provider-specific.

Related errors


AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11). Data as JSON: /api/errors/12bbcd8864cd0867. Report an issue: GitHub.

Appendix: source

Thrown at src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs:1576

                    previousMaxLength,
                    currentMaxLength));
        }

        if (property.IsUnicode(storeObject) != duplicateProperty.IsUnicode(storeObject))
        {
            throw new InvalidOperationException(
                RelationalStrings.DuplicateColumnNameUnicodenessMismatch(
                    duplicateProperty.DeclaringType.DisplayName(),
                    duplicateProperty.Name,
                    property.DeclaringType.DisplayName(),
                    property.Name,
                    columnName,
                    storeObject.DisplayName()));
        }

        if (property.IsFixedLength(storeObject) != duplicateProperty.IsFixedLength(storeObject))
        {
            throw new InvalidOperationException(
                RelationalStrings.DuplicateColumnNameFixedLengthMismatch(
                    duplicateProperty.DeclaringType.DisplayName(),
                    duplicateProperty.Name,
                    property.DeclaringType.DisplayName(),
                    property.Name,
                    columnName,
                    storeObject.DisplayName()));
        }

        var currentPrecision = property.GetPrecision(storeObject);
        var previousPrecision = duplicateProperty.GetPrecision(storeObject);
        if (currentPrecision != previousPrecision)
        {
            throw new InvalidOperationException(
                RelationalStrings.DuplicateColumnNamePrecisionMismatch(
                    duplicateProperty.DeclaringType.DisplayName(),
                    duplicateProperty.Name,
                    property.DeclaringType.DisplayName(),

View on GitHub (pinned to 3a2006ef56)