1. マイグレーションファイル作成
$ php artisan make:migration create_posts_table
Created Migration: 2020_12_02_092200_create_possts_table
2. マイグレーションファイルを編集
database/migrations/2020_12_02_092200_create_posts_table.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePostsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('title')->default('');
$table->text('content')->default('');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('posts');
}
}
public function up()の中に書いていく。
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->bigIncrements('id');
/* ここから */
$table->string('title')->default('');
$table->text('content')->default('');
/* ここまで */
$table->timestamps();
$table->timestamps();
});
}
最後にデータベースに反映
$ php artisan migrate
Migration table created successfully.
Migrating: 2020_12_02_092200_create_posts_table
Migrated: 2020_12_02_092200_create_posts_table