-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Closed as not planned
Closed as not planned
Copy link
Description
Bug description
I have just upgraded my EF (identity) project to 9.0.6 and started running into the PendingModelChangesWarning error. In the process of debugging it I appear to have stumbled across what appears to be a bug in the implementation as it stands.
Not sure where this is most appropriate to log so I am going to log it both in EF core and the aspnetcore github.
Also this error message is awful, surely you can provide more information about specifically what is wrong?
Your code
The bug appears to be very easy to reproduce.
Create a new database context
`public sealed class DatabaseContextTest(DbContextOptions<DatabaseContextTest> options) : DbContext(options) {}`
run your first migrations:
`dotnet ef migrations add First_Migration`
Run: `await dbContext.Database.MigrateAsync();`
Seems to work fine.
Modify this back to what I essentially had:
`public sealed class DatabaseContextTest(DbContextOptions<DatabaseContextTest> options) : IdentityDbContext(options) {}`
or more specifically
`public sealed class DatabaseContextTest(DbContextOptions<DatabaseContextTest> options) : IdentityDbContext<ApplicationUser>(options) {}`
run your first migrations:
`dotnet ef migrations add First_Migration`
Run: `await dbContext.Database.MigrateAsync();`
and you get:
`An error was generated for warning 'Microsoft.EntityFrameworkCore.Migrations.PendingModelChangesWarning': The model for context 'DatabaseContextTest' has pending changes. Add a new migration before updating the database. See https://aka.ms/efcore-docs-pending-changes. This exception can be suppressed or logged by passing event ID 'RelationalEventId.PendingModelChangesWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.`Stack traces
An error was generated for warning 'Microsoft.EntityFrameworkCore.Migrations.PendingModelChangesWarning': The model for context 'DatabaseContextTest' has pending changes. Add a new migration before updating the database. See https://aka.ms/efcore-docs-pending-changes. This exception can be suppressed or logged by passing event ID 'RelationalEventId.PendingModelChangesWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.
Verbose output
EF Core version
9.0.6
Database provider
Microsoft.EntityFrameworkCore.SqlServer
Target framework
.NET 9.0
Operating system
No response
IDE
Visual Studio 2022