-
Bug
-
Resolution: Not a bug
-
Minor
-
None
-
4.3.2
-
None
-
MOODLE_403_STABLE
The XMLDB Editor provides suggested code that "should work" unless very special things are happening. When switching the nullability to NOTNULL, the XMLDB Editor supplies a `$dbman->change_field_notnull($table, $field);` line, which seems like it should work. However, in the - very common - situation where the field has rows with null values, the ALTER TABLE can fail because the new NOTNULL restriction is violated by existing data.
In MySQL, this presents as the "Data truncated for column" error which has been mentioned in a handful of previous Moodle Trackers and recently caused an issue in the plugin we maintain.
I would propose that the change_field_notnull() method be modified to mitigate some of these issues. If the field is being set to NOTNULL and there is a default value, then the NULL values in that column should be set to the new default value.