“Laravel 8 Migrasi Kunci Asing” Kode Jawaban

Buat kunci fit untuk migrasi menggunakan Laravel 8

$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

Rollback migrasi Laravel

To rollback one step:

php artisan migrate:rollback

To rollback multiple steps:

php artisan migrate:rollback --step=[x]
  
To drop all tables and reload all migrations:

php artisan migrate:fresh
Angry Albatross

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 8 Migrasi Kunci Asing

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

Migrasi Laravel Kunci Asing

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

Jawaban yang mirip dengan “Laravel 8 Migrasi Kunci Asing”

Pertanyaan yang mirip dengan “Laravel 8 Migrasi Kunci Asing”

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

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya