![](https://www.searchlight8.com/wp/wp-content/uploads/2020/04/coding-1853305_1920-wpp1707394275457-870x580.jpg)
usersテーブルとpostsテーブルをリレーションしたいとき、postsテーブルにuse_idというカラムを作成して、usersのidと結びつけます。
このとき、postsのマイグレーションで下記のように設定します。
0 1 2 3 4 5 |
Schema::create('articles', function (Blueprint $table) { $table->unsignedBigInteger('user_id'); $table->foreign('user_id')->references('id')->on('users'); }); |
unsignedBigIntegerのところがポイントで、unsignedをつけないとマイグレーションでエラーになりました。