Foreign Key Repair Loop
This loop identifies and repairs broken foreign key relationships in a relational database. It systematically detects constraint violations, proposes correct…
This loop identifies and repairs broken foreign key relationships in a relational database. It systematically detects constraint violations, proposes correct…
This loop is republished with attribution. Full credit and the original content belong to the source linked above.
Real data. Real impact.
Emerging
Developers
Per week
Excellent
One command unlocks capabilities that would take hours to build.
Goal: Restore referential integrity by ensuring all foreign key constraints are valid across related tables Exit condition: All foreign key constraints validate successfully with no orphaned or invalid references Max iterations: 10 Check command:
Execute database integrity validation (e.g., PRAGMA foreign_key_check for SQLite, or equivalent for your RDBMS)
Agents: claude-code
Start the "Foreign Key Repair Loop" loop. Goal: Restore referential integrity by ensuring all foreign key constraints are valid across related tables Max iterations: 10 Between iterations run: Execute database integrity validation (e.g., `PRAGMA foreign_key_check` for SQLite, or equivalent for your RDBMS) Exit when: All foreign key constraints validate successfully with no orphaned or invalid references Begin by running the database integrity check command to identify any current foreign key violations. For each violation found, analyze whether it's due to missing parent records, orphaned children, or incorrect reference values. Generate appropriate SQL fixes (INSERT, UPDATE, or DELETE) to resolve each issue safely. Apply these changes within a transaction, then re-run the integrity check. Continue this cycle until all foreign key constraints pass validation or you reach 10 iterations. Prioritize preserving existing data over destructive operations. Self-pace this loop. After each iteration, run `Execute database integrity validation (e.g., `PRAGMA foreign_key_check` for SQLite, or equivalent for your RDBMS)` and evaluate the output, and only continue if the exit condition is not met (All foreign key constraints validate successfully with no orphaned or invalid references). Stop when the exit condition passes or 10 iterations are reached. Give a short status update each pass.
proprietary
Copy this prompt and run it with your agent to start the loop.
Start the "Foreign Key Repair Loop" loop.
Goal: Restore referential integrity by ensuring all foreign key constraints are valid across related tables
Max iterations: 10
Between iterations run: Execute database integrity validation (e.g., `PRAGMA foreign_key_check` for SQLite, or equivalent for your RDBMS)
Exit when: All foreign key constraints validate successfully with no orphaned or invalid references
Begin by running the database integrity check command to identify any current foreign key violations. For each violation found, analyze whether it's due to missing parent records, orphaned children, or incorrect reference values. Generate appropriate SQL fixes (INSERT, UPDATE, or DELETE) to resolve each issue safely. Apply these changes within a transaction, then re-run the integrity check. Continue this cycle until all foreign key constraints pass validation or you reach 10 iterations. Prioritize preserving existing data over destructive operations.
Self-pace this loop. After each iteration, run `Execute database integrity validation (e.g., `PRAGMA foreign_key_check` for SQLite, or equivalent for your RDBMS)` and evaluate the output, and only continue if the exit condition is not met (All foreign key constraints validate successfully with no orphaned or invalid references). Stop when the exit condition passes or 10 iterations are reached. Give a short status update each pass.1,500+ AI skills, agents & workflows. Install in 30 seconds. Part of the Torly.ai family.
© 2026 Torly.ai. All rights reserved.