Create Foreign id

 <?php


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('student_subjects', function (Blueprint $table) {
$table->id();
$table->foreignId('student_id')->constrained('students')->cascadeOnDelete()->cascadeOnUpdate();
$table->foreignId('subject_id')->constrained('subjects')->cascadeOnUpdate();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('student_subjects');
// Schema::dropIfExists('student_subjects',function(Blueprint $table){
// $table->dropConstrainedForeignId('student_id');
// $table->dropColumn('student_id');
// });

}
};

Comments