0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【自分用メモ】Laravel マイグレーションしてみた

Posted at

マイグレーション手順

1. マイグレーションファイル作成

今回はコーヒー豆銘柄のテーブルを作成する。
php artisan make:migration create_blands_table --create=blands

2. カラム追加

upメソッドで新規テーブル、カラム、インデックスを追加する。
今回カラムとして以下の通り設定する。
(1) 銘柄ID
(2) 銘柄ステータス
(3) 銘柄名
(4) 生産国
(5) 評価
(6) 作成日時
(7) 更新日時

yyyy_mm_dd_hhmmss_create_blands_table.php
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('blands', function (Blueprint $table) {
            $table->increments('id')->index()->comment('銘柄ID');
            $table->string('status', 50)->index()->default('active')->comment('銘柄ステータス');
            $table->string('name', 50)->index()->comment('銘柄名');
            $table->string('country', 50)->index()->comment('生産国');
            $table->string('comment', 254)->comment('評価');
            $table->timestamps();
        });
    }

3. マイグレーション

php artisan migrate

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?