“Laravel Kunci Asing” Kode Jawaban

Kunci Asing dalam Migrasi Laravel

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

Laravel Kunci Asing

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();
});
Courageous Cod

Kunci Asing di Laravel

// one_line code for foreign in laravel
$table->foreignId('user_id')->constrained()->onDelete('cascade');
Enthusiastic Emu

Tambahkan Kolom Kunci Asing Laravel 5.8

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

Buat migrasi Laravel Kunci Asing

Schema::table('posts', function (Blueprint $table) {
    $table->unsignedBigInteger('user_id');

    $table->foreign('user_id')->references('id')->on('users');
});
Super Starling

Laravel Kunci Asing

//acording to laravel 7>=

Schema::table('posts', function (Blueprint $table) {
    $table->foreignId('user_id')->constrained();
});

//for deffirent table
$table->foreignId('user_id')->constrained('users');

//for taking action
$table->foreignId('user_id')
      ->constrained()
      ->onUpdate('cascade')
      ->onDelete('cascade');
hansal

Jawaban yang mirip dengan “Laravel Kunci Asing”

Pertanyaan yang mirip dengan “Laravel Kunci Asing”

Lebih banyak jawaban terkait untuk “Laravel Kunci Asing” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya