0

I want to change some table columns in Laravel from nullable to having a default value. I installed doctrine/dbal, and created a new migration with the following columns I want to change (previously nullable):

public function up()
    {
        Schema::table('movies', function (Blueprint $table) {
            $table->string('movieDirector')->default('')->change();
            $table->string('movieGenre')->default('')->change();
            $table->string('movieCast')->default('')->change();
        });
    }

However this doesn't seem to have done anything. Is it possible to do? Thanks!

Aejg
  • 71
  • 2
  • 8

1 Answers1

1

You need to create a new migration using command:

php artisan make:migration update_movies_table

Then, in that created migration class, add this line, using the change method like this :

public function up()
    {
        Schema::table('movies', function (Blueprint $table) {
            $table->string('movieDirector')->default('test')->change();
            $table->string('movieGenre')->default('test')->change();
            $table->string('movieCast')->default('test')->change();
        });
    }

To make these changes and run the migration, use the command:

php artisan migrate
STA
  • 30,729
  • 8
  • 45
  • 59