{"record":{"id":"344f9171d67d97bc","repo":"dotnet/efcore","slug":"the-indexes-index1-on-entitytype1-and-index-344f91","errorCode":null,"errorMessage":"The indexes {index1} on '{entityType1}' and {index2} on '{entityType2}' are both mapped to '{table}.{indexName}', but with different uniqueness configurations.","messagePattern":"The indexes (.+?) on '(.+?)' and (.+?) on '(.+?)' are both mapped to '(.+?)\\.(.+?)', but with different uniqueness configurations\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Metadata/Internal/RelationalIndexExtensions.cs","lineNumber":85,"sourceCode":"        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(),\n                        duplicateIndex.DisplayName(),\n                        duplicateIndex.DeclaringEntityType.DisplayName(),\n                        index.DeclaringEntityType.GetSchemaQualifiedTableName(),\n                        index.GetDatabaseName(storeObject)))\n                : false\n            : (index.IsDescending is null) != (duplicateIndex.IsDescending is null)\n            || (index.IsDescending is not null\n                && duplicateIndex.IsDescending is not null\n                && !index.IsDescending.SequenceEqual(duplicateIndex.IsDescending))\n                ? shouldThrow\n                    ? throw new InvalidOperationException(\n                        RelationalStrings.DuplicateIndexSortOrdersMismatch(\n                            index.DisplayName(),\n                            index.DeclaringEntityType.DisplayName(),\n                            duplicateIndex.DisplayName(),","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Metadata/Internal/RelationalIndexExtensions.cs#L67-L103","documentation":"Thrown by RelationalIndexExtensions.AreCompatible when two same-named indexes on the same table have matching columns but disagree on IsUnique. A physical database index is either unique or not, so EF rejects two conflicting uniqueness configurations under one name.","triggerScenarios":"Lines 83-93: index.IsUnique != duplicateIndex.IsUnique after columns already matched. Typically from calling IsUnique() on one HasIndex but not the matching one across two table-sharing entity types.","commonSituations":"Table splitting where one entity declares a unique index and the co-mapped entity declares the same index non-unique; a derived type overriding uniqueness without changing the index name; copy-pasting index configs and forgetting the IsUnique call.","solutions":["Apply IsUnique() (or omit it) consistently on every index that shares the database name.","If the uniqueness genuinely differs, the indexes are different — give them distinct HasDatabaseName values.","Consolidate the index declaration onto the principal entity type of the shared table."],"exampleFix":"// before\nmodelBuilder.Entity<User>().HasIndex(u => u.Email).IsUnique().HasDatabaseName(\"IX_Email\");\nmodelBuilder.Entity<UserProfile>().HasIndex(u => u.Email).HasDatabaseName(\"IX_Email\"); // non-unique -> throws\n\n// after\nmodelBuilder.Entity<UserProfile>().HasIndex(u => u.Email).IsUnique().HasDatabaseName(\"IX_Email\");","handlingStrategy":"validation","validationCode":"// Assert uniqueness agreement for same-named indexes on a shared table\nvar group = from et in model.GetEntityTypes()\n            from idx in et.GetDeclaredIndexes()\n            where idx.GetDatabaseName() is string n\n            group idx by idx.GetDatabaseName() into g\n            where g.DistinctBy(i => i.IsUnique).Count() > 1\n            select g.Name;\nif (group.Any()) throw new InvalidOperationException(\"Uniqueness mismatch on index: \" + string.Join(\", \", group));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Centralize unique-index declarations on the table's principal entity.","Review all HasIndex calls for a shared table in code review."],"tags":["relational","model-validation","index","unique-constraint"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}