-1

I created a migration that had a nullable, but then I realized that it should be default 0. Is there a way to change that with another migration.

Here is my original migration

Schema::table('items', function (Blueprint $table) {
    $table->unsignedBigInteger('total')->nullable();
});

and this is the migration I'm trying to run

Schema::table('items', function (Blueprint $table) {
    $table->unsignedBigInteger('total')->default(0);
});
Aurilie
  • 189
  • 3
  • 14
  • 1
    https://laravel.com/docs/8.x/migrations#updating-column-attributes read the doc please – Kamlesh Paul Nov 19 '20 at 04:37
  • don't know if this is good practice but if your database is new and is not live then you can make changes to existing migration instead of making another migration just to modify a column attribute and run that migration as fresh, Assuming you have seeders set up, because you'll lose data on running fresh migrations. – Akash Sarode Nov 19 '20 at 04:42
  • Does this answer your question? [Make column not nullable in a Laravel migration](https://stackoverflow.com/questions/14013832/make-column-not-nullable-in-a-laravel-migration) – miken32 Nov 19 '20 at 04:42

1 Answers1

-1

Reference Laravel 8.x documentation you can try this code to update column attributes

Schema::table('items', function (Blueprint $table) { $table->unsignedBigInteger('total')->default(0)->change(); });

Waqar Akram
  • 107
  • 5