简体   繁体   English

Laravel 5.4迁移中时间戳和nullableTimestamp之间的区别

[英]difference between timestamps and nullableTimestamps in Laravel 5.4 migration

According to Laravel documentation : 根据Laravel文档

  • $table->timestamps(); Adds nullable created_at and updated_at columns. 添加可为空的created_atupdated_at列。
  • $table->nullableTimestamps(); Nullable versions of the timestamps() columns. timestamps()列的可空版本。

I don't understand. 我不明白 In other words, what I read is: 换句话说,我读到的是:

  • A creates nullable columns A创建可为空的列
  • B is like A but it creates nullable columns BA一样A但是它创建了可为空的列

What did I miss? 我错过了什么?

Since Laravel 5.2 there is no difference. 从Laravel 5.2开始,没有区别。 If you look at the source you'll see that nullableTimestamps() is an alias for timestamps() 如果您查看源代码 ,将会看到nullableTimestamps()timestamps()的别名。

/**
 * Add nullable creation and update timestamps to the table.
 *
 * @return void
 */
public function timestamps()
{
    $this->timestamp('created_at')->nullable();
    $this->timestamp('updated_at')->nullable();
}

/**
 * Add nullable creation and update timestamps to the table.
 *
 * Alias for self::timestamps().
 *
 * @return void
 */
public function nullableTimestamps()
{
    $this->timestamps();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM