Changes between Initial Version and Version 4 of Ticket #24447
- Timestamp:
- Mar 4, 2015, 6:17:45 PM (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #24447
- Property Patch needs improvement set
- Property Triage Stage Unreviewed → Accepted
- Property Version master → 1.7
- Property Cc added
- Property Needs documentation set
- Property Summary Migrations do not execute create_fk_sql() when adding a foreign key to a field → Migrations do not add a FK constraint for an existing column
-
Ticket #24447 – Description
initial v4 1 Migrations failed when introducing foreign keys on existing fields.2 3 1 Pull request: https://github.com/django/django/pull/4235 4 Branch with fix: https://github.com/ganwell/django/tree/master_missing_create_fk_sql5 Branch with unittest but no fix: https://github.com/ganwell/django/tree/master_missing_create_fk_sql_fail6 2 7 3 Consider following model: … … 27 23 }}} 28 24 29 The second migration won't create the foreign key. This does not fail with sqlite! Because these migrations are handled differently. It will fail with MySQL and probably Postgres too. I wrote a unittest and tested it with MySQL: master_missing_create_fk_sql_fail fails and master_missing_create_fk_sql is ok.25 The second migration won't create the foreign key. This does not fail with sqlite! Because these migrations are handled differently. It will fail with MySQL and probably Postgres too. 30 26 31 The code didn't detect this case - if old_field.rel doesn't exist alter_field() must always create the foreign key and ONLY if .rel exists it must check .db_constraint, too. Since no .rel also means there was no foreign key before. 32 33 I will of course redo the pull request to get clean history. I also fixed this in 1.7. 27 The code didn't detect this case: if old_field.rel doesn't exist alter_field() must always create the foreign key and ONLY if .rel exists it must check .db_constraint, too. Since no .rel also means there was no foreign key before.