From d218fcf07440414823b054323b2635a72686126d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=86=A0=E6=99=BA=20=7C=20Joe?= Date: Tue, 22 Mar 2022 14:55:34 +0800 Subject: [PATCH] Migration added foreignId method Laravel 7.x added foreignId method --- backend/laravel.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/laravel.php b/backend/laravel.php index 9a7f3c0..1e52b1c 100644 --- a/backend/laravel.php +++ b/backend/laravel.php @@ -380,8 +380,10 @@ $table->dropSpatialIndex('geo_location_spatialindex'); // Drop a spatial index f // FOREIGN KEY CONSTRAINTS -$table->foreign('user_id')->references('id')->on('users'); // Create foreign key constraints. -$table->dropForeign('posts_user_id_foreign'); // Drop foreign key (accepts an array of strings). +$table->foreign('user_id')->references('id')->on('users'); // Create foreign key constraints. +$table->foreignId('user_id')->constrained('users'); // Create foreign key terser methods (7.x). +$table->foreignId('user_id')->constrained()->onUpdate('cascade')->onDelete('cascade'); // Specify the desired action for the "on delete" and "on update" properties of the constraint(7.x). +$table->dropForeign('posts_user_id_foreign'); // Drop foreign key (accepts an array of strings). Schema::enableForeignKeyConstraints(); // Enable foreign key constraints within your migrations. Schema::disableForeignKeyConstraints(); // Disable foreign key constraints within your migrations.