{"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/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Metadata/Internal/RelationalIndexExtensions.cs#L52-L88","documentation":"Two indexes share the same database name and table but cover different columns. The database cannot have two indexes with the same name on different column sets.","triggerScenarios":"RelationalIndexExtensions.AreCompatible with shouldThrow:true when !columnNames.SequenceEqual(duplicateColumnNames). Triggered when HasDatabaseName gives the same name to indexes on different property sets mapped to the same table.","commonSituations":"Table-splitting where multiple entities define indexes on the shared table with a colliding name; explicit HasDatabaseName copy/paste errors; an owned entity's index colliding with the owner's index.","solutions":["Give each index a distinct HasDatabaseName.","Make the two indexes reference the same properties/columns if they are meant to be one index.","Drop the redundant index.","Re-check that an index on an owned type is not silently duplicating the owner's index."],"exampleFix":"// before\nmodelBuilder.Entity<Order>().HasIndex(o => o.CustomerId).HasDatabaseName(\"IX_Order_Customer\");\nmodelBuilder.Entity<OrderDetail>().ToTable(\"Order\").HasIndex(d => d.ProductId).HasDatabaseName(\"IX_Order_Customer\");\n\n// after\nmodelBuilder.Entity<Order>().HasIndex(o => o.CustomerId).HasDatabaseName(\"IX_Order_Customer\");\nmodelBuilder.Entity<OrderDetail>().ToTable(\"Order\").HasIndex(d => d.ProductId).HasDatabaseName(\"IX_Order_Product\");","handlingStrategy":"validation","validationCode":"// Detect index-name collisions with differing columns on the same table.\nvar groups = modelBuilder.Model.GetEntityTypes()\n    .SelectMany(e => e.GetDeclaredIndexes())\n    .GroupBy(i => new { Name = i.GetDatabaseName(), Table = i.DeclaringEntityType.GetSchemaQualifiedTableName() })\n    .Where(g => g.Count() > 1);\nforeach (var g in groups)\n{\n    var cols = g.Select(i => string.Join(\",\", i.Properties.Select(p => p.GetColumnName()))).Distinct();\n    if (cols.Count() > 1)\n        Console.WriteLine($\"Index '{g.Key.Name}' on '{g.Key.Table}' has conflicting column sets.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When table-splitting, assign distinct HasDatabaseName values to indexes on different properties.","Avoid sharing index names between owner and owned entities.","Validate the model in tests."],"tags":["ef-core","relational-metadata","index","model-validation","table-splitting"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}