Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP1stack specificStack: sql
sqlforeign-keysschemadata-integrity
Match a foreign key column's type exactly to the referenced primary key
Foreign key columns must use the same numeric type and signedness as the primary key they reference, so referential integrity and indexing work correctly.
PR: vinify-database-migrator · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codejavascript
| 1 | // parent.id is INTEGER UNSIGNED, but the FK is signed -> type mismatch |
| 2 | parent_id: { |
| 3 | type: Sequelize.INTEGER, |
| 4 | references: { model: { tableName: "parents" }, key: "id" }, |
| 5 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | // FK type mirrors the referenced PK exactly |
| 2 | parent_id: { |
| 3 | type: Sequelize.INTEGER.UNSIGNED, |
| 4 | references: { model: { tableName: "parents" }, key: "id" }, |
| 5 | } |
Explanation (EN)
Objašnjenje (HR)