マイグレーションファイルのみ作成
# マイグレーションファイルの生成
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