I have a SQLite database with the following migration defined:
Schema::create("views", function(Blueprint $table){
$table->integer("match_id");
$table->string("pov");
$table->string("teams");
$table->text("moves");
$table->bigIncrements("id");
$table->date("created_at");
$table->date("updated_at");
});
Note: id
is the primary key of the table, match_id
should just be treated as any other column.
This all works just fine, but I want match_id
to be nullable. I tried changing the $table -> integer("match_id")
to the following:
$table->integer("match_id")->nullable()->change();
//Also tried $table->integer("match_id")->nullable(true)->change();
I also ran ‘composer require doctrine/dbal’, which I saw online
When I try running php artisan migrate, it says there is nothing to migrate. And when I run php artisan migrate:fresh, for some reason the match_id column just doesn’t get added to the database at all, even though every other column works just fine. Any reason this might be?
2
Answers
Since
migrate:fresh
is an option (as pointed by @xenooooo), just edit your original migration to:This should fix the problem. With
migrate:fresh
you don’t need a second migration just to change, since it will drop all tables and create everything again. Also I’ve changed the order of the primary key (just in case of this be the problem ofmigrate:fresh
not creating thematch_id
column), and changed the timestamps format. In Laravel you don’t need to create manually the timestamps,"$table->timestamps()"
do it for you 🙂By using this
In Laravel 7
you can make "match_id" (nullable & integer) or foreign-key by using this code
As i used it in picture
here is code
and here is my db