You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PrecisionAttribute on Decimal parameter causes false positive for PendingModelChangesWarning exception #3521
Creating a migration works normally, but trying to apply it will result in PendingModelChangesWarning. Creating new migration afterwards results in an AlterColumn call for ScalingFactor that does not actually change anything.
The below is an AI-generated analysis and may contain inaccuracies.
Confirmed a PostgreSQL-provider bug on current main (3931c57), and on released Npgsql EF providers 10.0.3, 9.0.4 and 8.0.11. A model containing [Precision(9)] on decimal? ScalingFactor differs from its unchanged migration snapshot: the snapshot resolves to numeric(9,0), while the current model resolves to numeric(9). HasPendingModelChanges() returns true, and the model differ produces the spurious AlterColumnOperation shown in the report. No database connection is needed to reproduce this.
This is not a newly introduced EF 9 regression: the false model difference also occurs with EF/provider 8.0.11. EF 9's pending-model-change exception makes the existing problem more visible. I have not established an earlier working release.
The inconsistency is in Npgsql's numeric mapping round trip: [Precision(9)] produces numeric(9) with no configured scale; parsing that store type from the snapshot supplies PostgreSQL's implicit scale of zero, and the mapping subsequently renders numeric(9,0). These are equivalent PostgreSQL types. The fix should make that representation consistent without changing explicit scales or turning unconstrained numeric into a precision-constrained type.
The equivalent SQL Server 10.0.3 model, compared with its provider-specific snapshot (decimal(9,2)), reports no pending changes. The PostgreSQL [Precision(9, 0)] workaround is consistent with the successful explicit-scale regression cases.
No duplicate implementing PR or existing AI Triage comment was found. Upstream dotnet/efcore#35285 explains the EF 9 warning change, but does not fix this provider-specific mismatch. dotnet/efcore#29600 concerns precedence of explicit store-type facets, not this snapshot churn; preserving that precedence is important here.
minimal repro
Console program targeting .NET 10 with Npgsql.EntityFrameworkCore.PostgreSQL 10.0.3. The snapshot below represents the unchanged precision-only model. Expected output: False; actual output: True.
usingMicrosoft.EntityFrameworkCore;usingMicrosoft.EntityFrameworkCore.Infrastructure;usingMicrosoft.EntityFrameworkCore.Migrations;usingMicrosoft.Extensions.Logging;usingvarcontext=newTestContext();Console.WriteLine(context.Database.HasPendingModelChanges());publicclassTestContext:DbContext{protectedoverridevoidOnConfiguring(DbContextOptionsBuilderoptionsBuilder)=>optionsBuilder.UseNpgsql().LogTo(Console.WriteLine,LogLevel.Information).EnableSensitiveDataLogging();protectedoverridevoidOnModelCreating(ModelBuildermodelBuilder)=>modelBuilder.Entity<Parameter>().Property(e =>e.Id).ValueGeneratedNever();}publicclassParameter{publicintId{get;set;}[Precision(9)]publicdecimal?ScalingFactor{get;set;}}[DbContext(typeof(TestContext))]publicclassTestContextModelSnapshot:ModelSnapshot{protectedoverridevoidBuildModel(ModelBuildermodelBuilder){modelBuilder.HasAnnotation("Relational:MaxIdentifierLength",63);modelBuilder.UseIdentityByDefaultColumns();modelBuilder.Entity("Parameter", b =>{b.Property<int>("Id").HasColumnType("integer");b.Property<decimal?>("ScalingFactor").HasPrecision(9).HasColumnType("numeric(9)");b.HasKey("Id");b.ToTable("Parameter");});}}
Activity
roji commentedon Apr 14, 2025
Thanks, I can see this happening.
As a workaround, simply specify the scale as well:
Luk164 commentedon Apr 17, 2025
Thanks, that worked, and it also made me realize that I swapped meanings for precision and scale. I thought precision was for decimal count
roji commentedon Oct 21, 2026
AI Triage
The below is an AI-generated analysis and may contain inaccuracies.
Confirmed a PostgreSQL-provider bug on current
main(3931c57), and on released Npgsql EF providers 10.0.3, 9.0.4 and 8.0.11. A model containing[Precision(9)]ondecimal? ScalingFactordiffers from its unchanged migration snapshot: the snapshot resolves tonumeric(9,0), while the current model resolves tonumeric(9).HasPendingModelChanges()returnstrue, and the model differ produces the spuriousAlterColumnOperationshown in the report. No database connection is needed to reproduce this.This is not a newly introduced EF 9 regression: the false model difference also occurs with EF/provider 8.0.11. EF 9's pending-model-change exception makes the existing problem more visible. I have not established an earlier working release.
The inconsistency is in Npgsql's numeric mapping round trip:
[Precision(9)]producesnumeric(9)with no configured scale; parsing that store type from the snapshot supplies PostgreSQL's implicit scale of zero, and the mapping subsequently rendersnumeric(9,0). These are equivalent PostgreSQL types. The fix should make that representation consistent without changing explicit scales or turning unconstrainednumericinto a precision-constrained type.The equivalent SQL Server 10.0.3 model, compared with its provider-specific snapshot (
decimal(9,2)), reports no pending changes. The PostgreSQL[Precision(9, 0)]workaround is consistent with the successful explicit-scale regression cases.No duplicate implementing PR or existing AI Triage comment was found. Upstream dotnet/efcore#35285 explains the EF 9 warning change, but does not fix this provider-specific mismatch. dotnet/efcore#29600 concerns precedence of explicit store-type facets, not this snapshot churn; preserving that precedence is important here.
minimal repro
Console program targeting .NET 10 with
Npgsql.EntityFrameworkCore.PostgreSQL10.0.3. The snapshot below represents the unchanged precision-only model. Expected output:False; actual output:True.[10.0] Fix precision-only numeric migration snapshot churn (#4070)
[9.0] Fix precision-only numeric migration snapshot churn (#4069)
[8.0] Fix precision-only numeric migration snapshot churn (#4068)
Fix precision-only numeric migration snapshot churn (#4065)