efcore
efcore copied to clipboard
EF 8 migration 'up' method being executed twice. Undocumented breaking change?
EF Core version: 8.0.2 Database provider: Npgsql 8.0.2 Target framework: net8.0 Operating system: Windows
I have migrated an application from EF 7 to EF 8 and noticed that the behavior of migrations seems to have changed.
namespace Api.Migrations
{
/// <inheritdoc />
public partial class testmigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
Console.WriteLine("migrating");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}
The code above will only log 'migrating' once on EF 7 (and EF6) but is being executed twice on EF8. This is causing issues with custom migrations that execute non-idempotent logic in their 'up' command (eg creating a transaction and performing operations on the DB using an EF context rather than using the migration builder to generate the sql)
I couldn't find this change at https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-8.0/breaking-changes Is this expected behavior?
I can confirm, I came across the same error
same issue on my side with
- Npgsql 8.0.2
- Npgsql.EntityFrameworkCore.PostgreSQL 8.0.2
It's work well with Microsoft.EntityFrameworkCore.SqlServer 8.0.3
same issue on my side with
- Npgsql 8.0.0
- Npgsql.EntityFrameworkCore.PostgreSQL 8.0.0
I noticed that issue was reported a while ago: https://github.com/npgsql/efcore.pg/issues/3040
This is a PG-specific issue that was caused by https://github.com/npgsql/efcore.pg/issues/292 in 8.0 (trigger type reloading after new types are created in the database).
@maumar the cause here is the PG provider doing some special stuff, see https://github.com/npgsql/efcore.pg/issues/3040#issue-2055709863; it needs to go over the migrations that have been applied, in order to possibly reload types created by those applied migrations from the database. Hopefully we'd have a way for the provider to do that without building the migration twice.
Same goes for EF Core version: 9.0.0-preview3.24172.4 Database provider: Npgsql 9.0.0-preview.3 Target framework: net9.0
Sorry but it will be possible to have fix on target Framework net8.0 that is LTS ?
@Maleaume that's very unlikely, EF 8.0 only receives critical, low-risk bugfixes, and doesn't seem to meet that bar.
@roji, Thanks for the answer. I just have to know for tracability :)