Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mtctonyhkhk2010's avatar

Why $table->timestamps() puts 'ON UPDATE CURRENT_TIMESTAMP' on the created_at column?

I was trying to set a Message to read using this code

$message->update(['read' => true]);

However, this code updated both created_at and updated_at to current timestamp. I traced the problem and found ON UPDATE CURRENT_TIMESTAMP is set on the created_at column. After I disabled that, the code only update updated_at column as I wanted. So why the migration code $table->timestamps() puts 'ON UPDATE CURRENT_TIMESTAMP' on the created_at column?

0 likes
3 replies
thomaskim's avatar
Level 41

A lot of people seem to have this problem with the recent update.

Long story short, change ->timestamps() to one of these options:

// Option 1:
$table->nullableTimestamps();

// Option 2:
$table->timestamp('updated_at')->useCurrent();
$table->timestamp('created_at')->useCurrent();

You can read the discussion here: https://github.com/laravel/framework/issues/11518

4 likes

Please or to participate in this conversation.