Laravelで外部キーを設定する
忘れそうなのでメモ
user table
カラム | 型 |
---|---|
id | increments |
performance table
カラム | 型 |
---|---|
user_id | integer |
みたいなリレーションをもたせたいときのmigrationの書き方
performance tableへ変更を加えるmigrationファイル
public function up() { Schema::table('recipes', function (Blueprint $table) { $table->integer('user_id')->unsigned()->change(); $table->foreign('user_id')->references('id')->on('users'); }); }