[Laravel Sail]いつも忘れるやつ#3
マイグレーションファイル作成
sail artisan make:migration filename --table=tablename
up,downメソッドへの追記例1
/** * Run the migrations. */ public function up(): void { Schema::table('users', function (Blueprint $table) { $table->string('role')->after('name')->nullable(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('users', function (Blueprint $table) { $table->dropColumn('role'); }); }
up,downメソッドへの追記例2
/** * Run the migrations. */ public function up(): void { Schema::table('posts', function (Blueprint $table) { $table->foreignId('user_id'); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('posts', function (Blueprint $table) { $table->dropColumn('user_id'); }); }
up,downメソッドへの追記例3
/** * Run the migrations. */ public function up(): void { Schema::create('posts', function (Blueprint $table) { $table->id(); $table->string('title'); $table->text('body'); $table->timestamps(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::dropIfExists('posts'); }
マイグレーション
sail artisan migrate