How Can I Set the Default Value of a Timestamp Column to the Current Timestamp with Laravel Migrations?

前端 未结 9 1442
执笔经年
执笔经年 2020-11-27 10:21

I would like to make a timestamp column with a default value of CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP using the Laravel Schema Builder/Migrations. I hav

9条回答
  •  执笔经年
    2020-11-27 10:36

    This is how you do it, I have checked it and it works on my Laravel 4.2.

    $table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
    

    Hope this helps.

提交回复
热议问题