Changes between Initial Version and Version 2 of Ticket #33197


Ignore:
Timestamp:
Oct 14, 2021, 7:09:52 PM (3 years ago)
Author:
Jacob Walls
Comment:

Thanks for having a look. I see now the scope of #31826 was just for flows where the field is not renamed. So that makes this ticket a request to extend this to field renames, which looks like was discussed as 3 and 4 here.

I assume the issue goes away if you swap the order of operations in your migration?

If I switch the order to have AlterField followed by RenameField, FieldDoesNotExist is raised when migrating. These are the operations:

    operations = [
        migrations.RenameField(
            model_name='apple',
            old_name='core',
            new_name='core_renamed',
        ),
        migrations.AlterField(
            model_name='apple',
            name='core_renamed',
            field=models.BooleanField(db_column='core'),
        ),
    ]

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #33197

    • Property Triage Stage UnreviewedAccepted
    • Property Summary Providing prior implicit field name to db_column should be a noopRenaming field and providing prior field name to db_column should be an SQL noop
  • Ticket #33197 – Description

    initial v2  
    1 Similar to #31826, I would expect no migration changes detected when a `db_column` is added that matches the implicit field name. I tested with and without renaming the field on SQLite and MySQL 5.7.31. I'm not familiar enough with the review of #31826 to know whether these are distinct cases versus if it should be reopened.
     1Renaming a field and setting the prior implicit field name as the `db_column` to avoid db operations creates a migration emitting unnecessary SQL. Similar to #31826, which handled a very similar scenario but where there is no field rename, I would expect a SQL noop. I tested with SQLite and MySQL 5.7.31.
    22
    33{{{
     
    3232}}}
    3333
    34 Without renaming the field, follow the same flow and get an `AlterField` migration without SQL:
     34Without renaming the field, follow the same flow and get an `AlterField` migration without SQL, which is what #31826 intended:
    3535
    3636{{{
Back to Top