Skip to content

Commit 35b03c4

Browse files
authored
Update migration transaction docs to clarify EF Core 9 single-transaction behavior
1 parent 109ee1a commit 35b03c4

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

entity-framework/core/managing-schemas/migrations/applying.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ Note that `MigrateAsync()` builds on top of the `IMigrator` service, which can b
346346

347347
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.
348348

349+
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.
350+
349351
Migration locking applies when migrations are applied using any of the following methods:
350352

351353
* `dotnet ef database update` (.NET CLI)

entity-framework/core/managing-schemas/migrations/managing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ This can be used to manage any aspect of your database, including:
196196
* Triggers
197197
* Views
198198

199-
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`.
199+
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`.
200200

201201
## Remove a migration
202202

0 commit comments

Comments
 (0)