Skip to content

Commit 5cbe408

Browse files
committed
Don't throw PendingModelChangesWarning when applying a specific migration
Fixes #35342
1 parent 4b3e12f commit 5cbe408

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

src/EFCore.Relational/Migrations/Internal/Migrator.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.Transactions;
55
using Microsoft.EntityFrameworkCore.Diagnostics.Internal;
6-
using Microsoft.EntityFrameworkCore.Metadata.Internal;
76

87
namespace Microsoft.EntityFrameworkCore.Migrations.Internal;
98

@@ -94,7 +93,7 @@ public Migrator(
9493
public virtual void Migrate(string? targetMigration)
9594
{
9695
var useTransaction = _connection.CurrentTransaction is null;
97-
ValidateMigrations(useTransaction);
96+
ValidateMigrations(useTransaction, targetMigration);
9897

9998
using var transactionScope = new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled);
10099

@@ -219,7 +218,7 @@ public virtual async Task MigrateAsync(
219218
CancellationToken cancellationToken = default)
220219
{
221220
var useTransaction = _connection.CurrentTransaction is null;
222-
ValidateMigrations(useTransaction);
221+
ValidateMigrations(useTransaction, targetMigration);
223222

224223
using var transactionScope = new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled);
225224

@@ -349,7 +348,7 @@ await _migrationCommandExecutor.ExecuteNonQueryAsync(
349348
}
350349
}
351350

352-
private void ValidateMigrations(bool useTransaction)
351+
private void ValidateMigrations(bool useTransaction, string? targetMigration)
353352
{
354353
if (!useTransaction
355354
&& _executionStrategy.RetriesOnFailure)
@@ -365,7 +364,8 @@ private void ValidateMigrations(bool useTransaction)
365364
{
366365
_logger.ModelSnapshotNotFound(this, _migrationsAssembly);
367366
}
368-
else if (RelationalResources.LogPendingModelChanges(_logger).WarningBehavior != WarningBehavior.Ignore
367+
else if (targetMigration == null
368+
&& RelationalResources.LogPendingModelChanges(_logger).WarningBehavior != WarningBehavior.Ignore
369369
&& HasPendingModelChanges())
370370
{
371371
var modelSource = (ModelSource)_currentContext.Context.GetService<IModelSource>();

test/EFCore.SqlServer.FunctionalTests/Migrations/MigrationsInfrastructureSqlServerTest.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,7 @@ public async Task Empty_Migration_Creates_Database()
816816
{
817817
using var context = new BloggingContext(
818818
Fixture.TestStore.AddProviderOptions(
819-
new DbContextOptionsBuilder().EnableServiceProviderCaching(false))
820-
.ConfigureWarnings(e => e.Log(RelationalEventId.PendingModelChangesWarning)).Options);
819+
new DbContextOptionsBuilder().EnableServiceProviderCaching(false)).Options);
821820

822821
context.Database.EnsureDeleted();
823822
GiveMeSomeTime(context);

test/EFCore.SqlServer.FunctionalTests/Query/JsonQueryJsonTypeSqlServerFixture.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
2626
b =>
2727
{
2828
b.OwnsOne(x => x.OwnedReferenceRoot).ToJson("json_reference_custom_naming").HasColumnType("json");
29-
;
3029
b.OwnsMany(x => x.OwnedCollectionRoot).HasColumnType("json").ToJson("json_collection_custom_naming");
3130
});
3231

0 commit comments

Comments
 (0)