Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions entity-framework/core/managing-schemas/migrations/applying.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ Note that `MigrateAsync()` builds on top of the `IMigrator` service, which can b

Starting with EF Core 9, <xref:Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.MigrateAsync*> and <xref:Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate*> automatically acquire a database-wide lock before applying any migrations. This protects against database corruption that could result from multiple application instances running migrations concurrently, which is a common scenario when [applying migrations at runtime](#apply-migrations-at-runtime). The lock is held for the duration of the migration execution, including any [seeding code](xref:core/modeling/data-seeding#use-seeding-method), and is automatically released when the operation completes.

In addition, starting with EF Core 9, all pending migrations are applied within a single transaction. Prior to EF Core 9, each migration was wrapped in its own transaction. If any migration fails, the entire transaction is rolled back, leaving the database in the state it was in before `Migrate()` or `MigrateAsync()` was called.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Revert this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 8e8df09.

Migration locking applies when migrations are applied using any of the following methods:

* `dotnet ef database update` (.NET CLI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ This can be used to manage any aspect of your database, including:
* Triggers
* Views

In most cases, EF Core will automatically wrap each migration in its own transaction when applying migrations. Unfortunately, some migrations operations cannot be performed within a transaction in some databases; for these cases, you may opt out of the transaction by passing `suppressTransaction: true` to `migrationBuilder.Sql`.
In most cases, EF Core will automatically wrap migrations in a transaction when applying migrations. Prior to EF Core 9, each migration was wrapped in its own transaction. Starting with EF Core 9, all pending migrations are applied within a single transaction as part of [migration locking](xref:core/managing-schemas/migrations/applying#migration-locking). Unfortunately, some migration operations cannot be performed within a transaction in some databases; for these cases, you may opt out of the transaction by passing `suppressTransaction: true` to `migrationBuilder.Sql`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Make the changes here more concise as this behavior is only present in EF Core 9, in 10 it was reverted.
Make a low-impact breaking changes note for 9 for this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in the latest commit. managing.md now restores the original per-migration transaction text with a concise NOTE pointing to a new Low-impact breaking changes entry added to ef-core-9.0/breaking-changes.md that describes the EF Core 9-specific single-transaction behavior (and notes it was reverted in EF Core 10).


## Remove a migration

Expand Down