Skip to content

Revert "Use PRAGMA defer_foreign_keys instead of PRAGMA foreign_keys when migrating"#38120

Merged
cincuranet merged 1 commit intomainfrom
revert-35873-pragma-defer-fk
Apr 17, 2026
Merged

Revert "Use PRAGMA defer_foreign_keys instead of PRAGMA foreign_keys when migrating"#38120
cincuranet merged 1 commit intomainfrom
revert-35873-pragma-defer-fk

Conversation

@cincuranet
Copy link
Copy Markdown
Contributor

Reverts #35873.
Fixes #37598.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Reverts the SQLite migrations behavior introduced in #35873 by switching back from PRAGMA defer_foreign_keys to toggling PRAGMA foreign_keys during table rebuild migrations, addressing the data-loss scenario described in #37598.

Changes:

  • Update SQLite migrations SQL generation to emit PRAGMA foreign_keys = 0/1 with transaction suppression around rebuild drop/rename steps.
  • Update SQLite migrations SQL generator unit tests to match the new PRAGMA output.
  • Update functional migration SQL assertions to include the disable/enable foreign keys PRAGMAs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/EFCore.Sqlite.Core/Migrations/SqliteMigrationsSqlGenerator.cs Replaces defer_foreign_keys with transaction-suppressed foreign_keys off/on operations around rebuild drop/rename.
test/EFCore.Sqlite.FunctionalTests/Migrations/SqliteMigrationsSqlGeneratorTest.cs Updates expected SQL strings to assert PRAGMA foreign_keys = 0 before drop/rename and = 1 after.
test/EFCore.Sqlite.FunctionalTests/Migrations/MigrationsSqliteTest.cs Updates functional test SQL command expectations to include the new PRAGMA off/on commands.

Comment thread src/EFCore.Sqlite.Core/Migrations/SqliteMigrationsSqlGenerator.cs
Comment thread src/EFCore.Sqlite.Core/Migrations/SqliteMigrationsSqlGenerator.cs
@cincuranet cincuranet merged commit 554290f into main Apr 17, 2026
20 checks passed
@cincuranet cincuranet deleted the revert-35873-pragma-defer-fk branch April 17, 2026 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQLite defer_foreign_keys=ON still cascades deletes during table rebuilds (drop/rename), causing data loss

3 participants