File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -177,6 +177,52 @@ command (with exception of not being able to create a pivot model):
177177php artisan uuid:make:model Models/Post --all
178178```
179179
180+ ### Database migrations
181+
182+ The default primary ID column used in migrations will not work with UUID primary
183+ keys, as the default column type is an unsigned integer. UUIDs are 36 character
184+ strings so we must specify this in our migrations:
185+
186+ ``` php
187+ <?php
188+
189+ use Illuminate\Database\Migrations\Migration;
190+ use Illuminate\Database\Schema\Blueprint;
191+ use Illuminate\Support\Facades\Schema;
192+
193+ class CreateUsersTable extends Migration
194+ {
195+ /**
196+ * Run the migrations.
197+ */
198+ public function up(): void
199+ {
200+ Schema::create('users', function (Blueprint $table): void {
201+ // Primary key.
202+ $table->uuid('id')->primary();
203+ });
204+ }
205+ }
206+
207+ class CreatePostsTable extends Migration
208+ {
209+ /**
210+ * Run the migrations.
211+ */
212+ public function up(): void
213+ {
214+ Schema::create('posts', function (Blueprint $table): void {
215+ // Primary key.
216+ $table->uuid('id')->primary();
217+
218+ // Foreign key.
219+ $table->uuid('user_id');
220+ $table->foreign('user_id')->references('id')->on('users');
221+ });
222+ }
223+ }
224+ ```
225+
180226## Running the tests
181227
182228To run the test suite you can use the following commands:
You can’t perform that action at this time.
0 commit comments