This question already has answers here:
How Can I Set the Default Value of a Timestamp Column to the Current Timestamp with Laravel Migrations?
(11个答案)
5年前关闭。
我正在尝试实现以下功能:
此确切的代码失败了,因为
另一个问题是,我认为应该有更强大/更优雅的方式来解决此问题。那么,如何在迁移中正确设置默认的
看,如果有帮助。
(11个答案)
5年前关闭。
我正在尝试实现以下功能:
$table->dateTime('time')->default(new \DateTime());
此确切的代码失败了,因为
另一个问题是,我认为应该有更强大/更优雅的方式来解决此问题。那么,如何在迁移中正确设置默认的
DateTime
值? 最佳答案
试试这个:
$table->timestamp('time')->useCurrent = true;
看,如果有帮助。