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

Migrations: Side-effects when adding reference to Npgsql.EntityFrameworkCore.PostgreSQL #1587

Closed
mortenab opened this issue Nov 23, 2020 · 3 comments

Comments

@mortenab
Copy link

mortenab commented Nov 23, 2020

Hi,

We are using EF migrations with a code-first approach. Our application targets multiple database providers, including Postgres and SQL Server.
We generate the migrations as described in the Microsoft docs here: https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/providers?tabs=dotnet-core-cli#using-multiple-context-types
This has worked fine until we upgraded to .NET 5.

Now we experience that having the Npgsql.EntityFrameworkCore.PostgreSQL reference present in the csproj file has side effects for the SQL Server migrations. If we remove the reference, the SQL Server behavior is back to normal.

Repro steps

  1. Unzip the small the repro example Repro.zip
  2. Run dotnet ef migrations add InitialCreate and notice that the InitialCreate migration looks fine.
  3. Run dotnet ef migrations add New and notice that the New migration has an AlterColumn() for all primary keys in the entities. This is unexpected.
  4. Delete the Migrations folder, remove the reference to Npgsql.EntityFrameworkCore.PostgreSQL and re-run step 2 and 3 again, notice that the AlterColumn() calls no longer appear in the SQL Server migrations.

I know that the issue does not affect the Postgres migrations and therefore the bug might not seem relevant to this repository. If you think the issue is with the main EF Core libraries, I am happy to move it to that project instead.

Thanks,

Morten

@roji
Copy link
Member

roji commented Nov 24, 2020

Thanks @mortenab, I've filed this as dotnet/efcore#23456 to discuss with the EF team - it's clear why this is happening, and it's also possible to work around this by explicitly specifying the provider's extension class (though that's admittedly pretty bad).

A better strategy is probably to have two fully-separate separate migration projects, each only referencing one provider - see this docs on this.

@mortenab
Copy link
Author

Hi @roji - thanks for the quick reply 👍
I think we will go with the "separate migration projects" workaround.

@roji
Copy link
Member

roji commented Nov 25, 2020

Am going to close this as covered by dotnet/efcore#23456

@roji roji closed this as completed Nov 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants