Skip to content

Commit ea004d1

Browse files
committed
Document foreign key constraint naming changes
Add upgrade documentation explaining the new auto-generated FK constraint naming behavior introduced in #1041 and #1042, including: - New consistent naming pattern across all adapters - Potential impact on existing migrations with rollbacks - Conflict resolution with counter suffixes - Database-specific name length limits
1 parent 6d4b00d commit ea004d1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

docs/en/upgrading.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,40 @@ insertOrSkip() for Seeds
130130
New ``insertOrSkip()`` method for seeds to insert records only if they don't already exist,
131131
making seeds more idempotent.
132132

133+
Foreign Key Constraint Naming
134+
=============================
135+
136+
Starting in 5.x, when you use ``addForeignKey()`` without providing an explicit constraint
137+
name, migrations will auto-generate a name using the pattern ``{table}_{columns}``.
138+
139+
Previously, MySQL would auto-generate constraint names (like ``articles_ibfk_1``), while
140+
PostgreSQL and SQL Server used migrations-generated names. Now all adapters use the same
141+
consistent naming pattern.
142+
143+
**Impact on existing migrations:**
144+
145+
If you have existing migrations that use ``addForeignKey()`` without explicit names, and
146+
later migrations that reference those constraints by name (e.g., in ``dropForeignKey()``),
147+
the generated names may differ between old and new migrations. This could cause
148+
``dropForeignKey()`` to fail if it's looking for a name that doesn't exist.
149+
150+
**Recommendations:**
151+
152+
1. For new migrations, you can rely on auto-generated names or provide explicit names
153+
2. If you have rollback issues with existing migrations, you may need to update them
154+
to use explicit constraint names
155+
3. The auto-generated names include conflict resolution - if ``{table}_{columns}`` already
156+
exists, a counter suffix is added (``_2``, ``_3``, etc.)
157+
158+
**Name length limits:**
159+
160+
Auto-generated names are truncated to respect database limits:
161+
162+
- MySQL: 61 characters (64 - 3 for counter suffix)
163+
- PostgreSQL: 60 characters (63 - 3)
164+
- SQL Server: 125 characters (128 - 3)
165+
- SQLite: No limit
166+
133167
Migration File Compatibility
134168
============================
135169

0 commit comments

Comments
 (0)