diff --git a/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs b/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs index f14704b2584..c8ce2e1f100 100644 --- a/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs +++ b/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs @@ -621,6 +621,9 @@ protected virtual IEnumerable Add( createTableOperation.UniqueConstraints.AddRange( target.GetKeys().Where(k => !k.IsPrimaryKey()).SelectMany(k => Add(k, diffContext)) .Cast()); + createTableOperation.CheckConstraints.AddRange( + target.GetCheckConstraints().SelectMany(c => Add(c, diffContext)) + .Cast()); foreach (var targetEntityType in target.EntityTypes) { diff --git a/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs b/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs index df471020595..47956196665 100644 --- a/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs +++ b/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs @@ -240,6 +240,7 @@ public void Create_table() x.Property("ParentAltId"); x.HasOne("Node").WithMany().HasForeignKey("ParentAltId"); x.HasIndex("ParentAltId"); + x.HasCheckConstraint("SomeCheckConstraint", "[Id] > 10"); }), upOps => { @@ -255,7 +256,7 @@ public void Create_table() Assert.Null(createTableOperation.Columns.First(o => o.Name == "AltId").DefaultValue); Assert.NotNull(createTableOperation.PrimaryKey); Assert.Equal(1, createTableOperation.UniqueConstraints.Count); - Assert.Equal(0, createTableOperation.CheckConstraints.Count); + Assert.Equal(1, createTableOperation.CheckConstraints.Count); Assert.Equal(1, createTableOperation.ForeignKeys.Count); Assert.IsType(upOps[2]);