create文を作成するファイルを生成コマンド
php artisan make:migration create_books_table --create=books
database/migrations
の下にファイルが生成される。
<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateBooksTable extends Migration { /** * マイグレーションした時の動作 * * @return void */ public function up() { Schema::create('books', function (Blueprint $table) { $table->increments('id'); $table->timestamps(); }); } /** * マイグレーション取り消し時の動作. * * @return void */ public function down() { Schema::dropIfExists('books'); } }
テーブル作成時に、項目を変更したい場合は
<?php /** * マイグレーションした時の動作 * * @return void */ public function up() { Schema::create('books', function (Blueprint $table) { $table->increments('id'); $table->string('name', 50); $table->integer('price'); $table->string('author', 50)->nullable(); $table->timestamps(); }); }
マイグレーション開始コマンド
php artisan migrate
ロールバック)
php artisan migrate:rollback
マイグレーション全取り消し
php artisan migrate:reset
コメント