Answered by : imran-lashari
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
Source : | Last Update : Mon, 28 Jun 21
Answered by : splendid-stoat-wyg10kuj7db2
update your `integer('user_id')` to `bigInteger('user_id')`
public function up() { Schema::create('evaluation', function (Blueprint $table) { $table->increments('id'); $table->bigInteger('user_id')->unsigned()->index(); $table->timestamps(); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); }); }
Source : https://stackoverflow.com/questions/54990828/why-is-creating-foreign-key-in-laravel-5-8-failing | Last Update : Thu, 04 Nov 21
Answered by : super-starling-627qnc5imhfr
Schema::table('posts', function (Blueprint $table) { $table->unsignedBigInteger('user_id'); $table->foreign('user_id')->references('id')->on('users');
});
Source : | Last Update : Mon, 22 Feb 21
Answered by : nicola-ricciardi
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
Source : https://stackoverflow.com/questions/26437342/laravel-migration-best-way-to-add-foreign-key | Last Update : Tue, 30 Aug 22
Answered by : combative-coyote-v5z73ezio210
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
Schema::table('posts', function (Blueprint $table) { $table->unsignedBigInteger('user_id'); $table->foreign('user_id')->references('id')->on('users');
});
Source : https://laravel.com/docs/8.x/migrations | Last Update : Wed, 23 Dec 20
Answered by : super-starling-627qnc5imhfr
$table->foreign('column_name')->references('id')->on('table_name')->onDelete('cascade');
Source : | Last Update : Fri, 12 Feb 21
Answered by : maniruzzaman-akash
$table->foreignId('post_id') ->constrained() ->onUpdate('cascade') ->onDelete('cascade');
Source : https://devsenv.com/tutorials/ajax-with-laravel-api-and-more-learn-laravel-beyond-the-limit | Last Update : Sun, 25 Jul 21
Answered by : hurt-hedgehog-v5rwm3uogutt
Schema::table('posts', function (Blueprint $table) { $table->foreignId('user_id')->constrained();
});
Source : https://laravel.com/docs/8.x/migrations#foreign-key-constraints | Last Update : Mon, 01 Nov 21
Answered by : you
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddForeignKeyToTable extends Migration
{ /** * Run the migrations. * * @return void */ public function up() { Schema::table('your_table_name', function (Blueprint $table) { $table->foreign('foreign_key_column')->references('referenced_column')->on('referenced_table')->onDelete('cascade'); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::table('your_table_name', function (Blueprint $table) { $table->dropForeign(['foreign_key_column']); }); }
}
Source : | Last Update : Tue, 19 Sep 23