Solution for "laravel model foreign key"

$table->unsignedBigInteger('user_id'); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

foreign key in laravel migration

Schema::table('posts', function (Blueprint $table) { $table->unsignedBigInteger('user_id'); $table->foreign('user_id')->references('id')->on('users'); }); OR Schema::table('posts', function (Blueprint $table) { $table->foreignId('user_id')->constrained(); });

laravel foreign key

$table->foreign('column_name')->references('id')->on('table_name')->onDelete('cascade');

foreign key laravel migration

public function up() { Schema::create('replies', function (Blueprint $table) { $table->bigIncrements('id'); $table->text('body'); $table->unsignedBigInteger('question_id'); $table->integer('user_id')->unsigned(); $table->foreign('question_id')->references('id')->on('questions')->onDelete('cascade'); $table->timestamps(); }); }

laravel foreign key constraint

$table->foreignId('user_id') ->constrained() ->onUpdate('cascade') ->onDelete('cascade');

laravel foreign key

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'); }); }

add foreign key column laravel 5.8

Similar codes for "laravel model foreign key"


Latest 'PHP' questions

Added before "laravel model foreign key"