Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-80822

XMLDB Editor / DDL: Changing the default to NOTNULL can break upgrades

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not a bug
    • Icon: Minor Minor
    • None
    • 4.3.2
    • Database SQL/XMLDB
    • 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.

            dobedobedoh Andrew Lyons
            jrchamp Jonathan Champ
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.