• 
      

    Add field type change support in each database backend.

    Review Request #12233 — Created April 8, 2022 and submitted

    Information

    Django Evolution
    release-2.x

    Reviewers

    This updates the MySQL, Postgres, and SQLite database backends to
    support changing the types of a field.

    Both MySQL and Postgres build upon the common code, building SQL for
    altering the field type, and letting the common code handle constraint
    management. This is more complicated in the case of Postgres, where we
    also need to backup/restore the AUTO INCREMENT state, and need to
    cast field types. MySQL does not appear to require either of these
    operations.

    The SQLite support, as per usual, requires a full table rebuild in order
    to change columns. This completely overrides the common code, going
    through our standard table rebuild logic. There isn't much that's needed
    here, since we already have machinery set up for determining how to
    replace an existing field, and the type isn't really special in this
    regard. The only addition to the logic is a new CHANGE COLUMN TYPE
    operator that's passed in order to set the right field state.

    Upcoming changes will introduce ChangeField support for invoking this
    behavior, along with unit tests.

    Unit tests pass when used with the other in-progress changes.

    Summary ID
    Add field type change support in each database backend.
    This updates the MySQL, Postgres, and SQLite database backends to support changing the types of a field. Both MySQL and Postgres build upon the common code, building SQL for altering the field type, and letting the common code handle constraint management. This is more complicated in the case of Postgres, where we also need to backup/restore the `AUTO INCREMENT` state, and need to cast field types. MySQL does not appear to require either of these operations. The SQLite support, as per usual, requires a full table rebuild in order to change columns. This completely overrides the common code, going through our standard table rebuild logic. There isn't much that's needed here, since we already have machinery set up for determining how to replace an existing field, and the type isn't really special in this regard. The only addition to the logic is a new `CHANGE COLUMN TYPE` operator that's passed in order to set the right field state. Upcoming changes will introduce `ChangeField` support for invoking this behavior, along with unit tests.
    19f8f4c9b437df4f23a0b3706c865f8086bd8be0
    Description From Last Updated

    F841 local variable 'alter_table_items' is assigned to but never used

    reviewbotreviewbot
    Checks run (1 failed, 1 succeeded)
    flake8 failed.
    JSHint passed.

    flake8

    david
    1. Ship It!
    2. 
        
    chipx86
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to release-2.x (4c6aaec)