Changing column in Laravel migration causes exception: Changing columns for table requires Doctrine DBAL
Asked Answered
P

4

54

I'm trying to change the max length of one of my columns in table reserves in one migration. The code looks like this:

public function up()
{
    //
    Schema::table('reserves', function($table){
        $table->string("mobile", 11)->change();
    });
}

But when running the migration via artisan, it throws an exception and says:

[RuntimeException] Changing columns for table "reserves" requires Doctrine DBAL; install "doctrine/dbal".

What is the problem and how can I solve it?

Perversity answered 21/4, 2016 at 21:19 Comment(0)
P
124

The problem was solved by executing the following command on the root directory of the framework:

composer require doctrine/dbal
Perversity answered 21/4, 2016 at 21:32 Comment(4)
Why this is not installed by default?Honeyed
@Honeyed It's not installed by default because the designers wanted to keep it out of the framework because they see these as more of an edge case. You can always just pull it in if you need it so they opted to keep it out of the core framework to avoid bloat. I can't say I agree, I use it all the time, but that's the reason.Varmint
Note that you may encounter the "Class 'Doctrine\DBAL\Driver\PDOMySql\Driver' not found" error. Therefore, add the phrase " doctrine / dbal ":" ^ 2.0 ", to the composer file.Dur
Would be probably helpful to cite the docs: Before modifying a column, be sure to add the doctrine/dbal dependency to your composer.json file.Gabrila
P
3

add to composer.json

"require": {
        ...
        "doctrine/dbal": "*"
    },

run "composer update" command

Pile answered 12/3, 2020 at 19:8 Comment(0)
S
0

or if you can't install the library then:

        DB::statement('ALTER TABLE `reserves` MODIFY mobile varchar(11)');
Silhouette answered 5/9, 2022 at 10:56 Comment(0)
S
0

There are many ways to update the column name

Option 1: Install doctrine/dbal package via composer

composer require doctrine/dbal

Note: If you don't want to install a package then use go to option 2.

Option 2: use DB::statement with alter query to update a column

DB::statement('ALTER TABLE reserves MODIFY COLUMN mobile VARCHAR(11)');
  
Squeamish answered 30/10, 2023 at 11:43 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.