Issue Bug Closed

#105498Nullable table fields can not be migrated (ALTERed) to "NOT NULL" in an update from v12 to v13

Benjamin Franzke 10/28/24, 15:22 updated 08/12/25, 14:35

Description

Example: fe_users.image
This field has been changed from TINYTEXT DEFAULT NULL (in v12) to INT UNSIGNED DEFAULT NOT NULL (in v13).

That means the following ALTER TABLE statement is generated:

ALTER TABLE `fe_users` CHANGE `image` `image` INT UNSIGNED DEFAULT 0 NOT NULL

Which fails with:

 Error: Data truncated for column 'image' at row 1

When there are columns (which was fine in v12) with null values:

select uid, pid, username, image from fe_users;
+-----+------+--------------------------+-------+
| uid | pid  | username                 | image |
+-----+------+--------------------------+-------+
|   1 |  178 | styleguide-frontend-demo | NULL  |
|   2 |  205 | styleguide-frontend-demo | NULL  |
|   3 |  771 | example_user             | NULL  |
|   4 | 1008 | admin                    | 0     |
|   5 | 1013 | admin                    | NULL  |
+-----+------+--------------------------+-------+

Desired solution:

There should be an upgrade wizard that runs prior to this database updates, that sets all values of current nullable fields to the schema default value, when the desired schema is a non-nullable field with a default value.

Reviews 3