-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQL Server uniquifies index names globally, when only per-table is needed #27651
Comments
Related to #23144 |
Same issue when using Pomelo.EntityFrameworkCore.MySql provider - EF Core tries to rename existing indexes, even though their names are explicitly set via Fluent API. |
Description
When adding (via migration) a new index with the same explicit name as an existing index, indexes get needlessly renamed. Most of the time, the existing index gets renamed to Existing_Index1. Index names are per-table in SQL Server. There is no need to rename the new index, much less the existing one. This may be different on other database engines, like SQLite.
The existing logic, which is probably somewhere in the core, could move to the database adapter. Alternatively, the user could be made to handle this conflict.
Code
https://github.com/fuzzykiller/ef-core-migrations-index (The code is in a state where
dotnet ef migrations add AddHourIndex
can be run to demonstrate the behavior.)The relevant change, adding an index with the same name on a different entity:
Then running
dotnet ef migrations add AddHourIndex
results in the existing indexIX_Name_Unique
getting renamed toIX_Name_Unique1
.Verbose output
Provider and version information
EF Core version: 6.0.3
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: Windows 10 Enterprise 21H2
IDE: Rider 2021.3.3
The text was updated successfully, but these errors were encountered: