EF Core: The Model Has Pending Changes (Causes and Fixes)

Last updated: October 27, 2026 · Tested with .NET 10.0.12 (SDK 10.0.401), EF Core 10.0.14 with SQLite, dotnet-ef 10.0.14 (and EF Core 8.0.10 for the upgrade test), Windows 11

Short answer: since EF Core 9, Migrate() and dotnet ef database update throw PendingModelChangesWarning when your model no longer matches the last migration’s snapshot. Usually you changed an entity and forgot dotnet ef migrations add; add the migration and the error is gone. If it comes back after every new migration, a HasData call uses DateTime.Now or Guid.NewGuid(). If it appears right after a Git merge, two branches added migrations and the snapshot lost one of them. I reproduced all three in fresh projects, plus what happens when you suppress the warning instead.

Message ends with Cause Fix
has pending changes. Add a new migration before updating the database. Entity changed, no migration added dotnet ef migrations add <Name>
changes each time it is built. DateTime.Now, Guid.NewGuid() etc. in HasData Use constant seed values, then add one migration
has pending changes right after merging two branches The model snapshot kept only one branch’s change Add a migration, then empty its Up and Down
No error, but later SQLite Error 1: 'no such column: b.Rating' The warning was suppressed Remove the suppression, add the migration

The Error

The full exception, from a console app that calls MigrateAsync():

Unhandled exception. System.InvalidOperationException: An error was generated for warning 'Microsoft.EntityFrameworkCore.Migrations.PendingModelChangesWarning': The model for context 'BlogDb' 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'.
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.ValidateMigrations(Boolean useTransaction, String targetMigration)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.MigrateAsync(String targetMigration, CancellationToken cancellationToken)

It is the same from the command line, where dotnet ef database update exits with code 1:

System.InvalidOperationException: An error was generated for warning 'Microsoft.EntityFrameworkCore.Migrations.PendingModelChangesWarning': The model for context 'BlogDb' 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'.

Before migrating, EF Core builds your current model and compares it with the model snapshot (<Context>ModelSnapshot.cs) saved by the last migrations add. If they differ, the migrations you are about to apply don’t describe your model, so EF Core 9 and later stop instead of creating a database that doesn’t match your code. EF Core 8 only logged a warning. Microsoft lists it as a high-impact change in the EF Core 9 breaking changes.

How I Tested It

A Python script creates a fresh console project for each scenario (EF Core 10.0.14 with SQLite), edits the model step by step and runs the real dotnet ef and dotnet run commands. The blocks below are copied from its output: > is the command, then what it printed. The starting model:

public class Blog
{
    public int Id { get; set; }
    public string Name { get; set; } = "";
}

public class BlogDb : DbContext
{
    public DbSet<Blog> Blogs => Set<Blog>();

    protected override void OnConfiguring(DbContextOptionsBuilder options)
    {
        options.UseSqlite("Data Source=blog.db");
    }

Cause 1: You Changed the Model and Forgot the Migration

After an Init migration was applied, I added one property and ran the app again without a new migration:

public int Rating { get; set; }

That gives the exception above. Before you change anything, confirm the cause with the command EF Core 8 added for exactly this:

> dotnet ef migrations has-pending-model-changes   (exit 1)
Changes have been made to the model since the last migration. Add a new migration.

> dotnet ef migrations add AddRating   (exit 0)

> dotnet ef migrations has-pending-model-changes   (exit 0)
No changes have been made to the model since the last migration.

> dotnet run -- migrate   (exit 0)
Migrated

Note the exit codes: 1 when something is pending, 0 when it isn’t. Put the command in CI and a forgotten migration fails the pull request instead of the deployment.

One surprise: a project with no migrations at all doesn’t throw. I changed the model in a project that never ran migrations add; Migrate() printed Migrated both times and created nothing, while the CLI check still caught it:

> dotnet run -- migrate   (exit 0)
Migrated

> dotnet ef migrations has-pending-model-changes   (exit 1)
Changes have been made to the model since the last migration. Add a new migration.

Cause 2: DateTime.Now or Guid.NewGuid() in HasData

Seed data with a value that changes on every run:

modelBuilder.Entity<Blog>().HasData(
    new Blog { Id = 1, Name = "Welcome", Created = DateTime.Now });

The migration is added without complaint, but Migrate() fails with a different message:

Unhandled exception. System.InvalidOperationException: An error was generated for warning 'Microsoft.EntityFrameworkCore.Migrations.PendingModelChangesWarning': The model for context 'BlogDb' changes each time it is built. This is usually caused by dynamic values used in a 'HasData' call (e.g. `new DateTime()`, `Guid.NewGuid()`). Add a new migration and examine its contents to locate the cause, and replace the dynamic call with a static, hardcoded value. 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'.

Adding another migration does not help; I tried. The new migration just stores the timestamp from the moment I ran the command, and the next run produces a different one:

protected override void Up(MigrationBuilder migrationBuilder)
{
    migrationBuilder.UpdateData(
        table: "Blogs",
        keyColumn: "Id",
        keyValue: 1,
        column: "Created",
        value: new DateTime(2026, 10, 27, 9, 58, 15, 463, DateTimeKind.Local).AddTicks(943));
}

Guid.NewGuid() in seed data fails with the same “changes each time it is built” message. The fix is a constant, then one more migration:

modelBuilder.Entity<Blog>().HasData(
    new Blog { Id = 1, Name = "Welcome", Created = new DateTime(2026, 1, 1, 0, 0, 0, DateTimeKind.Utc) });
> dotnet ef migrations add FixedSeedDate   (exit 0)
An operation was scaffolded that may result in the loss of data. Please review the migration for accuracy.

> dotnet ef migrations has-pending-model-changes   (exit 0)
No changes have been made to the model since the last migration.

> dotnet run -- migrate   (exit 0)
Migrated

For a Guid, hard-code it (new Guid("...")) the same way. Data that should really be created at run time doesn’t belong in HasData; see Microsoft’s data seeding page for the alternatives.

Cause 3: Two Branches Added Migrations

This one hits teams. Branch A adds Rating and an AddRating migration; branch B adds Url and an AddUrl migration. Both edit the same snapshot file, Git reports a conflict, and someone resolves it by keeping one side. I kept branch B’s snapshot, the most common resolution. Both migrations are present:

> dotnet ef migrations list   (exit 0)
20261027043020_Init
20261027043027_AddRating (Pending)
20261027043032_AddUrl (Pending)

But the snapshot doesn’t know about Rating, so Migrate() throws the “has pending changes” exception. The obvious fix, dotnet ef migrations add MergeBranches, generates this:

protected override void Up(MigrationBuilder migrationBuilder)
{
    migrationBuilder.AddColumn<int>(
        name: "Rating",
        table: "Blogs",
        type: "INTEGER",
        nullable: false,
        defaultValue: 0);
}

That adds a column the AddRating migration already adds, so the next run fails differently:

Unhandled exception. Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 1: 'duplicate column name: Rating'.

The merge migration exists only to bring the snapshot up to date. Keep it, but delete everything inside Up and Down:

public partial class MergeBranches : Migration
{
    /// <inheritdoc />
    protected override void Up(MigrationBuilder migrationBuilder)
    {
    }

    /// <inheritdoc />
    protected override void Down(MigrationBuilder migrationBuilder)
    {
    }
}
> dotnet run -- migrate query   (exit 0)
Migrated

> dotnet ef migrations has-pending-model-changes   (exit 0)
No changes have been made to the model since the last migration.

Microsoft’s migrations in team environments page describes the same merge migration.

Don’t Suppress It

The exception text tells you how to turn it off:

options.ConfigureWarnings(w => w.Ignore(RelationalEventId.PendingModelChangesWarning));

With that line and the Rating property still missing its migration, the app migrates and then fails on the first query, because the column was never created:

Migrated
Unhandled exception. Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 1: 'no such column: b.Rating'.

Suppressing it moves the error from deploy time to the first request that touches the column. The only case where I’d turn it off is a model that differs on purpose between environments, and then only after has-pending-model-changes has run in CI.

Upgrading From EF Core 8: Not a Cause on Its Own

Many reports of this error come right after an upgrade, so I tested that too: a migration created with EF Core 8.0.10 and dotnet-ef 8.0.10 on net8.0, then the project moved to net10.0 and EF Core 10.0.14:

modelBuilder.HasAnnotation("ProductVersion", "8.0.10");
> dotnet ef migrations has-pending-model-changes   (exit 0)
No changes have been made to the model since the last migration.

> dotnet run -- migrate   (exit 0)
Migrated

No error with int, decimal and DateTime properties. The upgrade only exposes problems that were already there: EF Core 8 logged a pending-changes warning nobody read, EF Core 9 and later throw. Run has-pending-model-changes after the upgrade; if it reports changes, look at what a new migration would contain before you apply it.

Checklist

  • Run dotnet ef migrations has-pending-model-changes first: exit 1 means the model and the snapshot differ.
  • Forgot a migration: dotnet ef migrations add <Name>.
  • “changes each time it is built”: replace DateTime.Now, DateTime.UtcNow and Guid.NewGuid() in HasData with constants.
  • After a merge: add a migration, empty its Up and Down, commit it with the snapshot.
  • Add the check to CI; don’t suppress the warning to get a deploy through.

If you apply migrations when the app starts, more replicas can run Migrate() at once since EF Core 9 takes a lock; why a separate migration step is still better is in the 12-factor ASP.NET Core guide.

Related: EF Core 11 breaking changes · EF Core tutorial: migrations and performance · ASP.NET Core Web API with EF Core · all ASP.NET Core tutorials

Similar Posts

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *