Skip to content
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

EF 8 migration 'up' method being executed twice #33279

Open
aaron-manning opened this issue Mar 10, 2024 · 9 comments
Open

EF 8 migration 'up' method being executed twice #33279

aaron-manning opened this issue Mar 10, 2024 · 9 comments

Comments

@aaron-manning
Copy link

aaron-manning commented Mar 10, 2024

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?

@mariuszkochanowski
Copy link

I can confirm, I came across the same error

@Maleaume
Copy link

Maleaume commented Mar 21, 2024

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

@souamaj
Copy link

souamaj commented Mar 21, 2024

same issue on my side with

  • Npgsql 8.0.0
  • Npgsql.EntityFrameworkCore.PostgreSQL 8.0.0

@mariuszkochanowski
Copy link

mariuszkochanowski commented Mar 26, 2024

I noticed that issue was reported a while ago: npgsql/efcore.pg#3040

@roji
Copy link
Member

roji commented Mar 26, 2024

This is a PG-specific issue that was caused by npgsql/efcore.pg#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 npgsql/efcore.pg#3040 (comment); 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.

@maumar maumar added this to the 9.0.0 milestone Apr 6, 2024
@PrincessLunaOfficial
Copy link

Same goes for
EF Core version: 9.0.0-preview3.24172.4
Database provider: Npgsql 9.0.0-preview.3
Target framework: net9.0

@Maleaume
Copy link

Sorry but it will be possible to have fix on target Framework net8.0 that is LTS ?

@roji
Copy link
Member

roji commented May 14, 2024

@Maleaume that's very unlikely, EF 8.0 only receives critical, low-risk bugfixes, and doesn't seem to meet that bar.

@Maleaume
Copy link

@roji, Thanks for the answer. I just have to know for tracability :)

@roji roji changed the title EF 8 migration 'up' method being executed twice. Undocumented breaking change? EF 8 migration 'up' method being executed twice May 15, 2024
@maumar maumar assigned roji and maumar and unassigned maumar Aug 8, 2024
@roji roji modified the milestones: 9.0.0, Backlog Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants