[vagrant@localhost myblog]$ php artisan make:model Comment –migration
Model created successfully.
Created Migration: 2018_09_09_162004_create_comments_table
databaseの中のmigrationファイル
commentのmigration fileを編集する。
use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateCommentsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('comments', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('post_id') $table->string('body') $table->timestamps(); $table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade'); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('comments'); } }
ここまで出来たらmigrateする。
[vagrant@localhost myblog]$ php artisan migrate
Migrating: 2018_09_09_162004_create_comments_table
Migrated: 2018_09_09_162004_create_comments_table
なんだこれー