I've upgraded my project references from:
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.31" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.31">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.31" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="3.1.31" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.31" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.31">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.2.7" />
to:
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.12">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="6.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.12">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.2" />
Now when I add a new database entity to my DbContext and run Add-Migration ... I get a load of RenameIndex calls in my Up and Down migration for existing tables, and I'm not sure why?
For example I have an existing table called trigger which has an index called IX_ConnectorEntry_Id but in the added migration Up method it wants to rename it to IX_trigger_ConnectorEntry_Id and in the Down method it wants to put it back to what it was before.
See:
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameIndex(
name: "IX_ConnectorEntry_Id",
table: "trigger",
newName: "IX_trigger_ConnectorEntry_Id");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameIndex(
name: "IX_trigger_ConnectorEntry_Id",
table: "trigger",
newName: "IX_ConnectorEntry_Id");
}
It's trying to add the database name into the index name for some reason and its doing this for 111 existing indexes. The only way I can seem to stop this from happening is to add an explicit HasDatabaseName(...) in the entity configuration.
See:
public class TriggerMap : IEntityTypeConfiguration<Trigger>
{
public void Configure(EntityTypeBuilder<Trigger> builder)
{
builder.HasIndex(t => t.ConnectorEntry_Id).HasDatabaseName("IX_ConnectorEntry_Id");
}
}
I've not found anywhere online that states there is a breaking change to the way default index names are generated when upgrading from EF Core 3.1 to EF Core 6.
Are the only options here to give in and let EF Core dictate my index names or have to manually set them with the explicit HasDatabaseName(...) ?