【发布时间】:2016-04-15 14:48:31
【问题描述】:
我正在使用Laravel Framework version 5.2.7。我创建了一个数据库迁移,如下所示:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateLessonsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('lessons', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->text('body');
$table->boolean('some_bool');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('lessons');
}
}
我进入虚拟机的MySql数据库并使用命令desc lessons;,这是我得到的:
我不明白为什么 created_at 和 updated_at 列将 NULL 作为 Default。
我去了 Laravel 5.2 文档,看到了这个:
$table->timestamps(); Adds created_at and updated_at columns.
$table->nullableTimestamps(); Same as timestamps(), except allows NULLs.
所以根据文档$table->timestamps(); 不应该允许NULL 作为Default。但我仍然得到created_at 和updated_at 列,其中NULL 作为Default。我糊涂了。请帮忙!!
【问题讨论】:
标签: php mysql laravel-5.2