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 3 years have passed since last update.

laravel マイグレーションを作る

0
Posted at

マイグレーションファイルのみ作成

# マイグレーションファイルの生成
php artisan make:migration <ファイル名> -create=<テーブル名>

// 作成例
php artisan make:migration create_create_target_users_table --table=target_users
//成功すると、マイグレーションファイルが database/migrations/ の直下に作成されます。

マイグレーションファイルの編集

    public function up()
    {
        Schema::create('target_users', function (Blueprint $table) {
            $table->id();
            $table->string('name')->nullable()->comment('氏名');
            $table->uuid('uuid')->comment('UUID');
            $table->string('email')->uniqe()->comment('メールアドレス');
            $table->timestamps();
        });
    }
//固定長文字列型(char)
$table->char('hello', 20)
//可変長文字列型(varchar)
$table->string('hello')
//整数型(int)
$table->integer('hello')
//日時型(datetime)
$table->dateTime('hello')
//タイムスタンプ型(timestamp)
$table->timestamp ('hello')
//※雛形に最初から記述されている$table->timestamps()とは異なります。
//$table->timestamps()はテーブルに登録日時と更新日時を記録するカラムを追加するための定義です。

マイグレーション実行

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?