93

When trying to run a migration I get the error Artisan migration

error:Class 'Doctrine\\DBAL\\Driver\\PDOMySql\\Driver' not found

I have read the questions here and also see the notes to add:

doctrine/dbal": "~2.3 in the requires section of composer.json

Github Bug Report

However, I don't understand what has happened. I created table a few days ago with no issue.

I can't figure out what to do after adding that dependency in composer.son.

I don't want to accidentally update any other packages.

Mahbub
  • 4,812
  • 1
  • 31
  • 34
Nancymic
  • 1,059
  • 1
  • 8
  • 10

18 Answers18

174

The doctrine/dbal dependency needs to be added to your composer.json

composer require doctrine/dbal

For more information check laravel #Modifying Columns

Mahbub
  • 4,812
  • 1
  • 31
  • 34
  • As an addition, i encountered this problem upon removing a debugbar dependency from composer.json. I did notice DBAL package being removed but it was no problem until i ran another migration. Once fireing `composer require` i then had a 'problem' with this: `composer/package-versions-deprecated` – mschr Jan 05 '22 at 12:28
93

In my case both composer install and composer install was not working giving a same error “Class 'Doctrine\DBAL\Driver\PDOMySql\Driver' not found”,

The changes that i made to make this workable are given below

composer.json file changed

 "doctrine/dbal": "^3.0",

this changed with

"doctrine/dbal": "^2.0",

then run the command

composer update 
Avinash Raut
  • 1,872
  • 20
  • 26
39

You have to downgrade the current version, this is what worked for me:

composer require doctrine/dbal:2.*
MiraTech
  • 1,108
  • 18
  • 35
15

If you using doctrine 3, downgrade to "doctrine/dbal": "^2.10.3"(I don't know does laravel updated migration tools for doctrine 3. If do, you should update laravel tools). They renamed class and Doctrine\\DBAL\\Driver\\PDOMySql\\Driver not exists

shivlal kumavat
  • 868
  • 1
  • 12
  • 28
15

Laravel

Who ever is facing this issue while having doctrine/dbal": "3.0" aleady required: downgrade it back to

"doctrine/dbal": "^2.10".

If you still face issues for example getting

Laravel\Passport\Bridge\AccessToken::__toString() must not throw an exception

You should require a prev version of lcobucci/jwt. It just got auto updated to 3.4, which caused these issues for me. Took me around 3-4 hours to track everything down to this. Hope it helps someone else too.

composer require lcobucci/jwt 3.3.3
Kjell Weibrecht
  • 151
  • 1
  • 3
13
# For Laravel 6x/7x:    
composer require doctrine/dbal:"^2.0"
    
# For Laravel >= 8x:    
composer require doctrine/dbal
DEV Tiago França
  • 1,271
  • 9
  • 9
  • Your answer could be improved with additional supporting information. Please "edit" to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center: https://stackoverflow.com/help/how-to-answer – nima Oct 29 '21 at 18:27
  • Thanks! This is what I needed, my project was running 7.x. – PatricNox Sep 29 '22 at 14:48
11

As already said, use composer require doctrine/dbal, if for whatever reason that doesn't work, use a lower version like composer require doctrine/dbal:^2.12.1 and then run composer dumpautoload -o.

xyLuz
  • 178
  • 1
  • 11
6

Run

composer update

It will install your missing packages like PDOMySql.

Or

Delete vendor folder and run

composer install
Mahendra Pratap
  • 3,174
  • 5
  • 23
  • 45
  • 1
    It will not install any "missing packages" it will install what's specified in your `composer.json` file. – miken32 Nov 16 '19 at 01:46
  • 1
    In my case just running "composer install" solved the issue for me. I am using Laravel 8.0.0 on windows 8.1 32bits. Thanks a lot for your help. – Donzoby Jan 06 '21 at 15:30
4

This message shows up if you want to edit column in a database.

To solve it do:

  • add doctrine/dbal dependency to composer.json
  • and use the composer require doctrine/dbal command
MBT
  • 21,733
  • 19
  • 84
  • 102
3

In my case, it was due to the version of php that did not meet the necessary requirements for that version of the package.

So, updating to any previous version is not the solution, you have to look at the requirements of each version of the package and confirm that your project complies with them.

Here the specification of the requirements: https://packagist.org/packages/doctrine/dbal#3.1.3

And the command to update the library would be:

composer require doctrine/dbal:number_of_your_indicated_version

For example:

composer require doctrine/dbal:^2.13.5
Caro Pérez
  • 476
  • 4
  • 4
3

Before modifying a column, be sure to add the doctrine/dbal dependency to your composer.json file. The Doctrine DBAL library is used to determine the current state of the column and create the SQL queries needed to make the specified adjustments to the column:

composer require doctrine/dbal
MRMP
  • 303
  • 2
  • 5
2

If you are using laravel 7 then please downgrade the "doctrine/dbal"

From

doctrine/dbal:"^3.1"

To

doctrine/dbal:"^2.0"

and then run

composer update

It works for me

2

just run

composer update

worked for me Laravel 8

1

I had the same problem with Laravel 8.

composer require doctrine/dbal
composer update 

didn't help me to solve the issue.

I used DB::statement('SQLQuery') to solve the issue. I used below code to rename the column.

public function up()
{
    Schema::table('customer_profile', function (Blueprint $table) {
      //  $table->renameColumn('user_type_id','plan_id');
    });
    DB::statement('ALTER TABLE `customer_profile` CHANGE `user_type_id` `plan_id` BIGINT(20) NOT NULL;');
}
-2

Can you share your current composer.json?

After composer.json update, you can execute composer install. It won't update existing packages (because of generated composer.lock), it'll only install new ones.

What has changes since your last migration?

It's the same project in the same directory? If so, it should be there.

Mateusz Sip
  • 1,280
  • 1
  • 11
  • 11
  • Hmm can't add that much code here. Well definitely nothing has changed. I am not sure how to run composer – Nancymic Nov 20 '15 at 02:44
  • https://getcomposer.org/ Install it, then check [How to use it](https://getcomposer.org/doc/00-intro.md#using-composer) and run composer install in your project directory. – Mateusz Sip Nov 20 '15 at 02:53
-2

OK thanks so much for the help. Stupidly, I had read that to do some other operations, that missing driver is called and I had tried to run a migration the other day to change a column name and what I completely forgot was that subsequent migrate runs are trying to still run that bad one. Once i remembered and deleted the update column name migration, my add table migration ran fine. With a project due in a few weeks, no package updates for me!!

Nancymic
  • 1,059
  • 1
  • 8
  • 10
-2

I saw this: To rename a column, you may use the renameColumn method on the Schema builder. Before renaming a column, be sure to add the doctrine/dbal dependency to your composer.json file:

it maybe work.

Silence
  • 303
  • 1
  • 2
  • 10
-2

if you are using PhpStorm editor for your project open Terminal tab and run this command:

composer require doctrine/dbal

enter image description here

also you can open command window in root of your project and run that command.

A Hashemi
  • 289
  • 2
  • 6