047-404-3740 info@ayane.co.jp
ページを選択

Larabelのマイグレーションファイルは、コマンドラインから以下で作成できます。

例 : customersテーブルを作成するマイグレーションファイル

$ php artisan make:migration create_customers_table --create=customers
Created Migration: 2020_03_23_050035_create_customers_table

 

作成されたファイルは PROJECT_ROOT/database/migrations/ 以下に配置されます。
内容は以下のようなものになります。

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCustomersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('customers', function (Blueprint $table) {
            $table->id();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('customers');
    }
}