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

Synchro's avatar

Changing timestamp columns with useCurrent

I have a migration that removes / adds automatic timestamp updating from created_at and updated_at columns (I have enabled the timestamp DBAL option in my config):

      //up 
       Schema::table(
            'users',
            static function (Blueprint $table) {
                $table->timestamp('created_at')
                    ->nullable()
                    ->default(null)
                    ->change();
                $table->timestamp('updated_at')
                    ->nullable()
                    ->default(null)
                    ->change();
            }
    //down
        Schema::table(
            'users',
            static function (Blueprint $table) {
                $table->timestamp('created_at')
                    ->nullable()
                    ->useCurrent()
                    ->change();
                $table->timestamp('updated_at')
                    ->nullable()
                    ->useCurrent()
                    ->useCurrentOnUpdate()
                    ->change();
            }
        );

The up change works fine, and the automatic update options are removed successfully, but adding them back on in the down migration doesn't work. I logged the queries and both schema changes generate exactly the same queries!

ALTER TABLE users CHANGE updated_at updated_at TIMESTAMP NULL DEFAULT NULL, CHANGE created_at created_at TIMESTAMP NULL DEFAULT NULL

As you can see, the ON UPDATE options are simply not there. Skipping the nullable calls doesn't help either.

Why don't useCurrent and useCurrentOnUpdate work in a schema change?

0 likes
2 replies
Nakov's avatar

Have you tried just adding one or the other, but not both?

$table->timestamp('updated_at')
    ->nullable()
    ->useCurrentOnUpdate()
    ->change();
Synchro's avatar

@Nakov Yes; neither work. I think I will have to resort to a raw query

Please or to participate in this conversation.