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

lukegalea16's avatar

Migration to remove default value and ON UPDATE CURRENT_TIMESTAMP()

Hi, I have a table with a timestamp field that has the default value to current_timestamp() and ON UPDATE CURRENT_TIMESTAMP() listed as extra. The ON UPDATE CURRENT_TIMESTAMP() is definitely causing me issues right now so I need to add a migration to remove this.

Can anyone guide me as to which migration I should use in this case?

Thanks!

0 likes
5 replies
Shivamyadav's avatar

Yeah! sure , try with this any one as you needed this will disable both time stamp created_at and as well as updated_at place this in your tables model file

public $timestamps = false;

or try this for disabel timestamps

$table->timestamps();

or try this ,and add manually created_at

$table->timestamp('created_at');

and then re run the migration command ..or rollback them first and re migrate it with a single command

Sinnbeck's avatar

Can you show the original migration for the field?

As far as I know there is no built in query to remove a default. But you can perhaps try

DB::statement('ALTER TABLE table_name ALTER column_name DROP DEFAULT;')

Edit: Apparently it should be possible by setting it as default(null) as well

public function up()
{
    Schema::table('client', function (Blueprint $table) {
        $table->date('date')->default(null)->change();
    });
}
2 likes
aknEvrnky's avatar

and I think when you assign a value for timestamp, it will not assign the current timestamp on update because of it is not using the default value anymore.

lukegalea16's avatar

Hi, thank you for your help. This is what worked for me!

public function up()
    {
        Schema::table('device_logs', function (Blueprint $table) {
            DB::statement('ALTER TABLE `device_logs` CHANGE `happened_at` `happened_at` TIMESTAMP NULL DEFAULT NULL');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('device_logs', function (Blueprint $table) {
            DB::statement('ALTER TABLE `device_logs` CHANGE `happened_at` `happened_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP');
        });
    }

Please or to participate in this conversation.