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 : 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 : muhammad-ariq-rafi
$table->foreign('category_id')->references('id')->on('categories')->onUpdate('cascade')->onDelete('cascade');
Source : https://github.com/MuhammadAriqRafi/alhidayah-logistics/blob/master/database/migrations/2022_01_30_075107_create_product_categories_table.php | Last Update : Tue, 14 Jun 22
Answered by : marco-tellez
$table->unsignedBigInteger('created_by');
$table->foreign('created_by')->references('id')->on('users');
Source : | Last Update : Thu, 26 May 22
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