Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Schema Builder Update Default Value

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

like image 530
kilrizzy Avatar asked Oct 11 '13 13:10

kilrizzy


1 Answers

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';");
like image 183
kilrizzy Avatar answered Oct 02 '22 19:10

kilrizzy