Changes between Initial Version and Version 4 of Ticket #24447
- Timestamp:
- 03/05/15 00:17:45 (9 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #24447
- Property Cc Markus Holtermann added
- Property Patch needs improvement set
-
Property
Summary
changed from
Migrations do not execute create_fk_sql() when adding a foreign key to a field
toMigrations do not add a FK constraint for an existing column
-
Property
Version
changed from
master
to1.7
- Property Needs documentation set
-
Property
Triage Stage
changed from
Unreviewed
toAccepted
-
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.