私はを使用してい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
。私はLaravel5.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
スキーマビルダーで$table->timestamp('created_at')
代わりにを使用する場合$table-timestamps()
、デフォルト値はになりCURRENT_TIMESTAMP
、ではありませんNULL
。
同様に、レコードの更新時刻を保存するには:$table->timestamp('updated_at')
。
違いは文字「s」だけであり、created_at
/ created
、updated_at
/などの列名を指定する必要がありますupdated
。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加