Download the code from Github and do a compare.
Jun 15, 2024
6
Level 1
column "foreign_key" doesn't exist in database
I am learning Laravel, YouTube "30 Days to Learn Laravel". In video number 12 at 05:51, if I click onto "Structure", there is no column named "foreign_key" in my SQLite database.
It is really difficult to find the bug, if I don't know, where to search.
This is the content of the file "2024_06_14_153747_create_tags_table.php" in the migration folder:
<?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('tags', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
Schema::create('job_tag', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(\App\Models\Job::class, 'job_listing_id')->constrained()->cascadeOnDelete();
$table->foreignIdFor(\App\Models\Tag::class)->constrained()->cascadeOnDelete();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('tags');
Schema::dropIfExists('job_tag');
}
};
After that I wrote "php artisan migrate:rollback && php artisan migrate" as shown in the YouTube video. But the column "foreign_key" doesn't show up.
And I can't continue learning. Where can I search?
Level 122
There shouldn't be a column called foreign_id, Thats something added by the program Jeff is using to display the tables (table plus I think)
1 like
Please or to participate in this conversation.