53

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?

Ahmad
  • 5,551
  • 8
  • 41
  • 57

3 Answers3

122

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

composer require doctrine/dbal
Ahmad
  • 5,551
  • 8
  • 41
  • 57
  • 39
    Why this is not installed by default? – NicuVlad Jul 23 '18 at 19:45
  • 19
    @NicuVlad 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. – nickc Aug 15 '19 at 15:29
  • 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. – ParisaN Apr 28 '21 at 21:50
  • Would be probably helpful to cite the [docs](https://laravel.com/docs/8.x/migrations#modifying-columns): `Before modifying a column, be sure to add the doctrine/dbal dependency to your composer.json file.` – Adam Aug 09 '21 at 07:39
3

add to composer.json

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

run "composer update" command

0

or if you can't install the library then:

        DB::statement('ALTER TABLE `reserves` MODIFY mobile varchar(11)');
Osama Alvi
  • 659
  • 4
  • 14