“Laravel 8 Migracja zagranicznych kluczowych” Kod odpowiedzi

Zrób klucz do migracji za pomocą Laravel 8

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

Laravel zagraniczny klucz

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

Rolowanie migracji 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

Utwórz migrację laravel zagranicznych kluczy

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

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

Laravel 8 Migracja zagranicznych kluczowych

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

Migracja laravel zagranicznych kluczy

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

Odpowiedzi podobne do “Laravel 8 Migracja zagranicznych kluczowych”

Pytania podobne do “Laravel 8 Migracja zagranicznych kluczowych”

Więcej pokrewnych odpowiedzi na “Laravel 8 Migracja zagranicznych kluczowych” w PHP

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu