{"record":{"id":"7239ecd95dbea846","repo":"dotnet/efcore","slug":"the-indexes-index1-on-entitytype1-and-index-7239ec","errorCode":null,"errorMessage":"The indexes {index1} on '{entityType1}' and {index2} on '{entityType2}' are both mapped to '{table}.{indexName}', but with different columns ({columnNames1} and {columnNames2}).","messagePattern":"The indexes (.+?) on '(.+?)' and (.+?) on '(.+?)' are both mapped to '(.+?)\\.(.+?)', but with different columns \\((.+?) and (.+?)\\)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Metadata/Internal/RelationalIndexExtensions.cs","lineNumber":70,"sourceCode":"            || duplicateColumnNames == null)\n        {\n            return shouldThrow\n                ? throw new InvalidOperationException(\n                    RelationalStrings.DuplicateIndexTableMismatch(\n                        index.DisplayName(),\n                        index.DeclaringEntityType.DisplayName(),\n                        duplicateIndex.DisplayName(),\n                        duplicateIndex.DeclaringEntityType.DisplayName(),\n                        index.GetDatabaseName(storeObject),\n                        index.DeclaringEntityType.GetSchemaQualifiedTableName(),\n                        duplicateIndex.DeclaringEntityType.GetSchemaQualifiedTableName()))\n                : false;\n        }\n\n        if (!columnNames.SequenceEqual(duplicateColumnNames))\n        {\n            return shouldThrow\n                ? throw new InvalidOperationException(\n                    RelationalStrings.DuplicateIndexColumnMismatch(\n                        index.DisplayName(),\n                        index.DeclaringEntityType.DisplayName(),\n                        duplicateIndex.DisplayName(),\n                        duplicateIndex.DeclaringEntityType.DisplayName(),\n                        index.DeclaringEntityType.GetSchemaQualifiedTableName(),\n                        index.GetDatabaseName(storeObject),\n                        FormatColumnNames(columnNames),\n                        FormatColumnNames(duplicateColumnNames)))\n                : false;\n        }\n\n        return index.IsUnique != duplicateIndex.IsUnique\n            ? shouldThrow\n                ? throw new InvalidOperationException(\n                    RelationalStrings.DuplicateIndexUniquenessMismatch(\n                        index.DisplayName(),\n                        index.DeclaringEntityType.DisplayName(),","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Metadata/Internal/RelationalIndexExtensions.cs#L52-L88","documentation":"Thrown by RelationalIndexExtensions.AreCompatible when two indexes share the same database name AND table, but resolve to different column lists (columnNames vs duplicateColumnNames differ per SequenceEqual). EF requires indexes that share one name on one table to describe the same column ordering, because they are one physical index in the database.","triggerScenarios":"Line 67-80 of RelationalIndexExtensions.cs: the null check passes (both indexes resolve to columns) but columnNames.SequenceEqual(duplicateColumnNames) is false. Produced when HasIndex with different property lists on two table-sharing entity types carries the same HasDatabaseName.","commonSituations":"Table-splitting two entities onto one table and giving both an index the same name but over different properties; renaming a property's column on one entity without updating the index; TPH/TPT where a base and derived index collide on name but cover different columns.","solutions":["Make the two indexes target the same properties (and the same column names via HasColumnName) so the resolved column lists match.","Give each index a distinct database name with HasDatabaseName.","Remove the redundant index from one entity type so only one definition exists for that name.","Verify with index.GetColumnNames(storeObject) on both sides that the column ordering now matches exactly."],"exampleFix":"// before\nmodelBuilder.Entity<Order>().HasIndex(o => o.CustomerId).HasDatabaseName(\"IX_Cust\");\nmodelBuilder.Entity<Refund>().HasIndex(r => r.OriginId).HasDatabaseName(\"IX_Cust\"); // same table, different columns -> throws\n\n// after\nmodelBuilder.Entity<Refund>().HasIndex(r => r.CustomerId).HasDatabaseName(\"IX_Cust\");","handlingStrategy":"validation","validationCode":"// Confirm two indexes sharing a database name resolve to identical column lists\nstatic bool ColumnsMatch(IReadOnlyIndex a, IReadOnlyIndex b, StoreObjectIdentifier so)\n    => a.GetDatabaseName(so) == b.GetDatabaseName(so)\n        && a.GetColumnNames(so) is { } ca\n        && b.GetColumnNames(so) is { } cb\n        && ca.SequenceEqual(cb);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When two entities share a table, define shared indexes in one place with the same property/column set.","Use HasColumnName consistently so column resolution does not silently drift.","Run a model-validation unit test that asserts no DuplicateIndex* exceptions."],"tags":["relational","model-validation","index","column-mapping"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}