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

PeregrineStudios's avatar

How can I stop Laravel from making timestamps `on update CURRENT_TIMESTAMP`?

I understand this default value existing on the created_at and updated_at columns, but why on every timestamp? How do I disable this default behaviour for my own timestamp columns?

0 likes
3 replies
Snapey's avatar

it wont mess with your columns?

Cronix's avatar
Cronix
Best Answer
Level 67

You need to make the datetime column nullable, then mysql won't add that. By default, mysql adds that to the first timestamp in the table, unless explicitly told not to (via allowing a null value for the field). This is a mysql thing, not a laravel thing.

$table->timestamp('colName')->nullable();

https://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html

Edit: I knew I read about this somewhere when it comes to laravel: https://ma.ttias.be/laravel-mysql-auto-adding-update-current_timestamp-timestamp-fields/

5 likes
mecjos's avatar

@Cronix what if I don't want it to be null... on my production server it sets it as current timestamp on update.. but at local server (homestead) it's normal. on production server mariaDB server is installed I guess that's reason but how to fix it?

1 like

Please or to participate in this conversation.