Skip to content

Commit 89b2687

Browse files
authored
Use PRAGMA defer_foreign_keys instead of PRAGMA foreign_keys when migrating (#35873)
1 parent 0e6e66c commit 89b2687

File tree

3 files changed

+55
-269
lines changed

3 files changed

+55
-269
lines changed

src/EFCore.Sqlite.Core/Migrations/SqliteMigrationsSqlGenerator.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ private IReadOnlyList<MigrationOperation> RewriteOperations(
458458
if (rebuilds.Any())
459459
{
460460
operations.Add(
461-
new SqlOperation { Sql = "PRAGMA foreign_keys = 0;", SuppressTransaction = true });
461+
new SqlOperation { Sql = "PRAGMA defer_foreign_keys = 1;" });
462462
}
463463

464464
foreach (var ((table, schema), _) in rebuilds)
@@ -475,12 +475,6 @@ private IReadOnlyList<MigrationOperation> RewriteOperations(
475475
});
476476
}
477477

478-
if (rebuilds.Any())
479-
{
480-
operations.Add(
481-
new SqlOperation { Sql = "PRAGMA foreign_keys = 1;", SuppressTransaction = true });
482-
}
483-
484478
foreach (var index in indexesToRebuild)
485479
{
486480
operations.Add(CreateIndexOperation.CreateFrom(index));

0 commit comments

Comments
 (0)