8
votes

Trying to setup a migration that will make my already existing "active" field have a default value of "1".

I see in the docs I can use something like:

$table->integer('active')->default(1);

But I tried this in my migration with no success, I guess because the field already exists. Is there a way to correctly manage existing fields using the schema builder?

My current migration:

public function up()
{
    Schema::table('scores', function($table){
        $table->integer('active')->default(1);
    });
}

Edit:

From what I've read so far, this can't be done with the query builder. But when I try to run a raw query:

DB::query("ALTER TABLE `scores` CHANGE COLUMN `active` `active` int(11) NOT NULL DEFAULT '1';");

I'm getting a "method 'query' does not exist error", so I'm guessing this method name was changed I just can't find what it was changed to

1

1 Answers

12
votes

Looks like DB::query() was changed to DB::statement()

This did the trick:

DB::statement("ALTER TABLE `scores` CHANGE COLUMN `active` `active` int(11) NOT NULL DEFAULT '1';");