Skip to content

fix modified column being nullable#1026

Open
LordSimal wants to merge 3 commits into5.xfrom
fix-modified-nullable
Open

fix modified column being nullable#1026
LordSimal wants to merge 3 commits into5.xfrom
fix-modified-nullable

Conversation

@LordSimal
Copy link
Contributor

Since we are now more tightly integrating the migrations plugin with the CakePHP framework I'd propose to change the default updated/modified column type to not be nullable, as by the TimestampBehavior this will always be set.

@LordSimal LordSimal added this to the 5.next milestone Feb 21, 2026
}
}
if ($onUpdate !== null && $onUpdate !== '') {
$column->setUpdate($onUpdate);
Copy link
Contributor Author

@LordSimal LordSimal Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markstory is this maybe a bug in the base schema dialect?

It didn't correctly detect the on update CURRENT_TIMESTAMP as it seems - but just for MySQL

Copy link
Contributor Author

@LordSimal LordSimal Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

found the issue - the Extra column in that describe query contains

DEFAULT_GENERATED on update CURRENT_TIMESTAMP

as you can see here

  [1] =>
  array(9) {
    'Field' =>
    string(7) "created"
    'Type' =>
    string(8) "datetime"
    'Collation' =>
    NULL
    'Null' =>
    string(2) "NO"
    'Key' =>
    string(0) ""
    'Default' =>
    string(17) "CURRENT_TIMESTAMP"
    'Extra' =>
    string(17) "DEFAULT_GENERATED"
    'Privileges' =>
    string(31) "select,insert,update,references"
    'Comment' =>
    string(0) ""
  }
  [2] =>
  array(9) {
    'Field' =>
    string(7) "updated"
    'Type' =>
    string(8) "datetime"
    'Collation' =>
    NULL
    'Null' =>
    string(2) "NO"
    'Key' =>
    string(0) ""
    'Default' =>
    string(17) "CURRENT_TIMESTAMP"
    'Extra' =>
    string(45) "DEFAULT_GENERATED on update CURRENT_TIMESTAMP"
    'Privileges' =>
    string(31) "select,insert,update,references"
    'Comment' =>
    string(0) ""
  }
mysql> SHOW FULL COLUMNS FROM table1;
+---------+--------------+-----------+------+-----+-------------------+-----------------------------------------------+---------------------------------+---------+
| Field   | Type         | Collation | Null | Key | Default           | Extra                                         | Privileges                      | Comment |
+---------+--------------+-----------+------+-----+-------------------+-----------------------------------------------+---------------------------------+---------+
| id      | int unsigned | NULL      | NO   | PRI | NULL              | auto_increment                                | select,insert,update,references |         |
| created | datetime     | NULL      | NO   |     | CURRENT_TIMESTAMP | DEFAULT_GENERATED                             | select,insert,update,references |         |
| updated | datetime     | NULL      | NO   |     | CURRENT_TIMESTAMP | DEFAULT_GENERATED on update CURRENT_TIMESTAMP | select,insert,update,references |         |
+---------+--------------+-----------+------+-----+-------------------+-----------------------------------------------+---------------------------------+---------+

@markstory
Copy link
Member

Do we still need all of this with the change made to cake core?

@LordSimal
Copy link
Contributor Author

Nope, will re-check this with latest 5.x

@LordSimal
Copy link
Contributor Author

So the change in cakephp/cakephp#19207 now causes these tests to fail as the serialized schema dumps do not contain that new property.

@markstory @dereuromark I have no idea how those schema-dump files are generated

@LordSimal LordSimal force-pushed the fix-modified-nullable branch from 2e1218f to 74800c7 Compare February 27, 2026 06:51
@markstory
Copy link
Member

I have no idea how those schema-dump files are generated

I usually just update those by hand 😊

@LordSimal LordSimal marked this pull request as ready for review March 1, 2026 09:36
@LordSimal
Copy link
Contributor Author

Thanks to Codex we now have a PHP script to automatically update all the Diff Schema Dump Files instead of having to manually adjust/update those serialized dump files whenever we decide/need to change something in our database class properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants