Fix adding new non-NULL fields when there's existing data on SQLite.

Review Request #11383 — Created Jan. 19, 2021 and submitted

Information

Django Evolution
release-2.x

Reviewers

Django Evolution 2.0 regressed adding non-NULL fields to a table
containing existing data. Previous versions would set the column to
allow NULL value in the temporary table, copy data over to it, create
the destination table with the current NULL flag, and copy data back.
2.0 changed this to follow the modern, recommended approach of creating
the proper schema for the temporary table, but that meant that the
column could no longer be left empty.

We now set the initial value as part of the INSERT statement, instead
of in a follow-up UPDATE statement. This is the same approach Django
chose, confirming that it's sound.

Some additional logic has been added to work around a data loss bug
that's been present (but never encountered in our use) for many years.
When going from a NULL to a non-NULL, we'd override any copied data with
initial data. Definitely not good. We now use the copied data if
available, and set an initial value if not.

All unit tests pass for all versions of Python and Django.

Summary ID
Fix adding new non-NULL fields when there's existing data on SQLite.
Django Evolution 2.0 regressed adding non-NULL fields to a table containing existing data. Previous versions would set the column to allow NULL value in the temporary table, copy data over to it, create the destination table with the current NULL flag, and copy data back. 2.0 changed this to follow the modern, recommended approach of creating the proper schema for the temporary table, but that meant that the column could no longer be left empty. We now set the initial value as part of the `INSERT` statement, instead of in a follow-up `UPDATE` statement. This is the same approach Django chose, confirming that it's sound. Some additional logic has been added to work around a data loss bug that's been present (but never encountered in our use) for many years. When going from a NULL to a non-NULL, we'd override any copied data with initial data. Definitely not good. We now use the copied data if available, and set an initial value if not.
28e48ae46180f9106d4350aab80e9306f608cc3f
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-2.x (16ad676)
Loading...