Changes between Initial Version and Version 3 of Ticket #30691


Ignore:
Timestamp:
Aug 9, 2019, 9:13:08 AM (5 years ago)
Author:
Simon Charette
Comment:

That's probably a bug in django.db.migrations.autodetector.MigrationAutodetector.generate_altered_fields's call to add_operation which doesn't pass any dependencies when new_field.is_relation and not old_field.is_relation. The dependencies can be retrieved by using self._get_dependencies_for_foreign_key(new_field).

We want to depend on the latest migration of the referenced app instead of the initial one though as the model we're referencing might have been altered since then but that's something the aforementioned method should handle.

Tests should be added to django/tests/migrations/test_autodetector.py.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #30691

    • Property Component UncategorizedMigrations
    • Property Triage Stage UnreviewedAccepted
    • Property Version 2.2master
    • Property Owner changed from nobody to Dart
    • Property Status newassigned
  • Ticket #30691 – Description

    initial v3  
    77# TestApp1(models.py):
    88
     9{{{#!python
    910class App1(models.Model):
    1011    id = models.UUIDField(primary_key=True, unique=True, default=uuid.uuid4, editable=False, verbose_name=_('identifier'))
    1112    text = models.CharField(max_length=100, verbose_name=_('text'))
    1213    another_app = models.UUIDField(null=True, blank=True, verbose_name=_('another app'))
     14}}}
    1315
    1416# TestApp2(models.py):
    1517
     18{{{#!python
    1619class App2(models.Model):
    1720    id = models.UUIDField(primary_key=True, unique=True, default=uuid.uuid4, editable=False, verbose_name=_('identifier'))
    1821    text = models.CharField(max_length=100, verbose_name=_('text'))
     22}}}
    1923
    2024First model named "App1" has UUID field named "another_app":
    2125
    22 another_app = models.UUIDField(null=True, blank=True, verbose_name=_('another app'))
     26`another_app = models.UUIDField(null=True, blank=True, verbose_name=_('another app'))`
    2327
    2428After some time i change field from UUID to FK, like this:
    2529
    26 - another_app = models.ForeignKey(App2, null=True, blank=True, on_delete=models.SET_NULL, verbose_name=_('another app'))
     30- `another_app = models.ForeignKey(App2, null=True, blank=True, on_delete=models.SET_NULL, verbose_name=_('another app'))`
    2731
    2832And as result i create new migration, but Migration class was unexpected result, because it does not create any "dependencies" for App2, because of FK.
Back to Top