artisan migration error "Class 'Doctrine\\DBAL\\Driver\\PDOMySql\\Driver' not found", - php

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.

The doctrine/dbal dependency needs to be added to your composer.json
composer require doctrine/dbal
For more information check laravel #Modifying Columns

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

You have to downgrade the current version, this is what worked for me:
composer require doctrine/dbal:2.*

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

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

# For Laravel 6x/7x:
composer require doctrine/dbal:"^2.0"
# For Laravel >= 8x:
composer require doctrine/dbal

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.

Run
composer update
It will install your missing packages like PDOMySql.
Or
Delete vendor folder and run
composer install

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

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

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

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

just run
composer update
worked for me Laravel 8

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;');
}

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.

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!!

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.

if you are using PhpStorm editor for your project open Terminal tab and run this command:
composer require doctrine/dbal
also you can open command window in root of your project and run that command.

Related

Laravel PackageManifest.php: Undefined index: name

I'm just trying to deploy my application and I just ran composer update on my server and I got the following error:
In PackageManifest.php line 122:
Undefined index: name
How can I fix this issue?
As a temporary fix, try this, it worked for me, in the following file:
vendor/laravel/framework/src/Illuminate/Foundation/PackageManifest.php
Find line 116 and comment it:
$packages = json_decode($this->files->get($path), true);
Add two new lines after the above commented line:
$installed = json_decode($this->files->get($path), true);
$packages = $installed['packages'] ?? $installed;
I had the same problem, I just execute the command:
composer update
this will updated the composer.lock file.
After that worked like a charm.
I found this issue on the composer GitHub repo that helped a lot
I updated my Laravel framework from 5.8 to 5.8.38, following the table displayed in that issue and the error disappeared.
This Laravel blog post also helps
If you can't upgrade Laravel, you can just stay with Composer 1 by running
composer self-update --1
I recently switched composer 2.0.8 and my Laravel version is 6.20.27
To solve this issue:
Step 1:
Delete compose.lock File
Step 2:
Install dependencies.
composer install
I had the same problem.
In my case downgrading the composer version fixed the problem.
They updated Composer 4 times within 2 days - I think they had a problem with their newest updates.
In my case version 1.10.1 was the version to go with.
sudo composer self-update --1
I hope it'll work.
I had a problem like this, and also tried composer self-update --stable, but there was no result. So, I found that this file belongs to the Laravel framework. So the following command resolved this issue:
$ composer update laravel/framework
In my case downgrading the composer version fixed the problem.
sudo composer self-update --1
https://github.com/composer/composer/issues/9340#issuecomment-716210369
As stated in here, your laravel version may conflict with composer 2
composer update laravel/framework
should fix your problem :D
The easiest way to solve this issue is
delete composer.lock file from your project.
Run composer install
I was facing the same issue. I Saw my Laravel framework version is "laravel/framework": "6.0"
So just put the cap before the version and it starts working fine.
"laravel/framework": "^6.0"
Running the following command worked for me. Maybe this will help someone needy.
composer update
I removed my vendor folder and composer.lock and ran composer install again. This solved it for me.
Running composer update worked for my project with Laravel 5.7
Some versions of composer give this error, the version 1.10.20 doesn't throw this error
composer self-update 1.10.20
composer install
For my Laravel 5.7 project deleting vendor folder and composer.lock file fixed the issue.
I have a solution:
Delete the vendor folder.
run composer install
Don't use --no-scripts. This will cause a problem, and will not create the appropiate folders which the file PackageManifest.php and others need.
run composer update
This is so you don't have problems with bugs in the file.
Try this, it is worked for me, in the following file:
vendor/laravel/framework/src/Illuminate/Foundation/PackageManifest.php
Find this line and comment on it
$packages = json_decode($this->files->get($path), true);
Add two new lines after the above-commented line
$installed = json_decode($this->files->get($path), true);
$packages = $installed['packages'] ?? $installed;
If you want to fix without making updates and composer updates
just go to vendor/composer and remove installed.json
Running the following command fixed it for us
composer self-update --stable
No need to force an upgrade on your packages (running composer update on production is not recommended anyway) or downgrade your Composer if it's on version 2.
If you have a website that requires Composer v1 for updates (because, for example, v2 causes errors) and you have version v2 installed globally, the quickest solution is:
Step 1
Download the latest stable 1.x composer.phar from https://getcomposer.org/download/ (under Manual Download).
Step 2
Place the downloaded composer.phar file in the root of your project (where the composer.json file resides).
Step 3
Run your command using the composer.phar file. Example:
php composer.phar install
To downgrade composer to an old version:
composer self-update <version>
Example:
composer self-update 1.10.1
here's a solution that worked for me. https://github.com/composer/composer/issues/9340#issuecomment-716210369
change your laravel framework to 6.18.7 so that its compatible with composer 2
If you have composer version 2 upgrade your laravel to 6.2.
https://github.com/composer/composer/issues/9340#issuecomment-716210369
I had the same problem after i clone an laravel project and start composer install. Then I read through some solutions here. In my opinion, it is not a good idea to edit the laravel core. But if it's just for testing, why not.
My solution in my case was composer update instead composer install. In the case of composer update, it does not use the composer.lock file and updates the packages from composer.json. For me and in my special case works.
On my computer composer version 2.0.9 was installed, I had the same problem when upgrade laravel project.
the solution is :
Delete Vendor folder inside your project if exist.
inside composer.json for laravel version write this "laravel/framework": "^6.0" don't forget ^ in front of 6.0 it needs to install latest version of laravel 6
then composer update
finally, it works perfectly.
I updated to Composer 2.0.11 and I had the error. Downgraded to Composer 1.10.20, it worked great, BUT IT'S VERY VERY SLOW.
So for those like me who don't want to change the vendor code, and still want Composer 2.0.x know that it was a kind of bug in Laravel, and Laravel has fixed it in minor versions (or hotfixes). I was using Laravel 5.7.9 and my vendor/laravel/framework/src/Illuminate/Foundation/PackageManifest.php ->build() was like:
if ($this->files->exists($path = $this->vendorPath.'/composer/installed.json')) {
$packages = json_decode($this->files->get($path), true);
}
But in Laravel 5.7.29 PackageManifest.php , the same file is fixed:
if ($this->files->exists($path = $this->vendorPath.'/composer/installed.json')) {
$installed = json_decode($this->files->get($path), true);
$packages = $installed['packages'] ?? $installed;
}
Same goes for Laravel 5.6.0 that had the bug, and is fixed in 5.6.40 Laravel 5.6.40 PackageManifest.php. I don't know from which minor version it has been fixed at each level, but I suggest to go for the last, like 5.7.29, 5.6.40 etc. Or you can go look the versions to see if it has been fixed.
NOW COMPOSER 2.0 IS VERY VERY FAST.
If the error is after self updating the composer, just replace composer with composer1.Just change:
composer install ...
into:
composer1 install ...
Just this!
I got this issue because of a Laravel and composer version are not compatible.
Following are the steps I follow to solve this issue:
I update Laravel version from 6.1 to 6.20 in composer.json file Eg: "laravel/framework": "6.20.*"
then delete composer.lock file.
And run composer install command
Now Problem is fixed. :)
run a composer upgrade.
This work for me on laravel 7

class 'Former\FormerServiceProvider' not found - Laravel

i'm trying to install the anahkiasen/former package once again but it won't work. The funny thing is, I downloaded it about a weak ago and it was working perfectly. My code if finished and use's this former package. I tried to install a new package a half hour ago and since this the former class isn't found anymore.
Like I mentioned it, it was working perfectly before, but since I did a composer update it doesn't work.
Well I did what they said over here:
https://github.com/formers/former/wiki/Getting-started
first I run this::
composer require anahkiasen/former:4.0.*#dev
then a composer update
after the update I add this in my config/app.php provider section:
Former\FormerServiceProvider::class,
and this in the alias section:
'Former' => 'Former\Facades\Former',
I tried it but it still doesn't work. Just getting
Class 'Former\FormerServiceProvider' not found
as an output
I removed the package I wanted to install before and found another way.. But the problem with the former class is still there.
Thanks for any help!
Terminal outputs:
/var/www/laravel# php composer.phar require anahkiasen/former
gives:
Using version ^4.0 for anahkiasen/former
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
-------- then I added the provider/alias --- after this:
composer update --no-scripts
gives
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
composer dump-autoload
gives of course:
Generating autoload files
/var/www/laravel/logs# php artisan config:publish anahkiasen/former
gives:
PHP Fatal error: Class 'Former\FormerServiceProvider' not found in /var/www/laravel/logs/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 146
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'Former\FormerServiceProvider' not found
note that I changed the directory in the last command
Let's start from the beginning.
Follow below steps:-
1) Run below command in terminal:-
composer.phar require anahkiasen/former
2) It'll ask you for the version, type dev-master
3) Add Former's service provider to your Laravel application in app/config/app.php. In the providers array add :
'Former\FormerServiceProvider',
Add then alias Former's main class by adding its facade to the aliases array in the same file :
'Former' => 'Former\Facades\Former',
4) run composer update --no-scripts
After that, run composer dump-autoload, and that should work.
If not working then run this command:-
php artisan config:publish anahkiasen/former
Hope it will help you :)

Composer Update Laravel

A developer has sent me his project to work with, but when ever I try to update or install my vendors everything works great until the very end and it outputs the message bellow.
C:\xampp\htdocs\BigWaveMedia\davinkit>php artisan migrate
{
"error": {
"type": "Exception",
"message": "expected color value: failed at `.clearfix;` C:\\xampp\\htdocs\\BigWaveMedia\\davinkit\\app\\start\/..\/..\/public\/less\/style.less on line 102",
"file": "C:\\xampp\\htdocs\\davinkit\\vendor\\leafo\\lessphp\\lessc.inc.php",
"line": 3258
}
}
C:\xampp\htdocs\BigWaveMedia\davinkit>
Any ideas at all? Here is a full log http://pastebin.com/y9q4Rc5z
When you run composer update, composer generates a file called composer.lock which lists all your packages and the currently installed versions. This allows you to later run composer install, which will install the packages listed in that file, recreating the environment that you were last using.
It appears from your log that some of the versions of packages that are listed in your composer.lock file are no longer available. Thus, when you run composer install, it complains and fails. This is usually no big deal - just run composer update and it will attempt to build a set of packages that work together and write a new composer.lock file.
However, you're running into a different problem. It appears that, in your composer.json file, the original developer has added some pre- or post- update actions that are failing, specifically a php artisan migrate command. This can be avoided by running the following: composer update --no-scripts
This will run the composer update but will skip over the scripts added to the file. You should be able to successfully run the update this way.
However, this does not solve the problem long-term. There are two problems:
A migration is for database changes, not random stuff like compiling assets. Go through the migrations and remove that code from there.
Assets should not be compiled each time you run composer update. Remove that step from the composer.json file.
From what I've read, best practice seems to be compiling assets on an as-needed basis during development (ie. when you're making changes to your LESS files - ideally using a tool like gulp.js) and before deployment.
The following works for me:
composer update --no-scripts
this is command for composer update please try this...
composer self-update
write this command in your terminal :
composer update
You can use :
composer self-update --2
To update to 2.0.8 version (Latest stable version)

Laravel 4 Package installation using composer

I need to know how to install packages in laravel 4.
I have downloaded a bundle from github, but executing the bundle, I see it is deprecated in Laravel 4. Can anyone please help me.
Just using packagist, you can go to packagist.org , after that just put the package name at require key in your composer.json on your laravel project, and that run this command , composer update or compose install
in example :
// composer.json
"require": {
// default value..
"intervention/image": "dev-master",
}
i hope this help
Laravel 4 now uses composer to install packages.
You can add new packages to laravel via a few options on composer. One is on the command line.
> composer require author/package
> dev-master
After issuing the require command it will ask you what version to use. then run composer update, add the PackageServiceProvider to your app/config/app.php
First and always if you plan to use composer in your work, learn the basics of it (what is composer.json,composer.lock...)
There is excellent video on Laracasts https://laracasts.com/lessons/you-must-use-composer
That way you can avoid problems and enjoy using this great package manager.
Next use composer dump(-autoload) command frequently and composer self-update.
If that bundle is deprecated in Laravel4 than it is deprecated and you can't use it ( unless author made some changes and adopt it for l4 )
Also bundle is a l3 specific type and in l4 we have packages.
Ok, you can't execute composer commands on windows command prompt. mac/linux terminal would do but if you insist on using windows then install this [https://www.cygwin.com/] so you could issue unix commands

Composer update "could not completely remove doctrine/dbal", Laravel 4 broken

I just did a Composer update on my Laravel 4 project, after which it completely broke down. It all started with Composer giving me the error "Could not completely remove doctrine/dbal", after which I tried the update again.
At that point the Artisan command php artisan clear-compiled, set to run before a Composer update, failed, saying the redirectIfTrailingSlash() method (called in bootstrap/start.php) does not exist.
So now my app is giving me the white screen of death, and Composer update/install can't fix it. I've tried removing the lock file and all packages in vendor. No dice.
More info:
I have no compiled.php file in the bootstrap folder. Artisan probably removed this before the first update that made everything fail.
My composer.json works, I have updated without trouble many times before.
I can run Composer if I use --no-scripts or comment out the redirectIfTrailingSlash() method call.
When I run composer update successfully, I get a lot of suggested packages to install, doctrine/dbal being among those. A successful composer update doesn't solve my problem, however.
The initial composer update was run from my development VM. I have no idea why it would have trouble removing packages, though.
Any help is welcome.
Did you try upgrading Laravel as there is no need for redirectIfTrailingSlash(). If so read the upgrade process here github.com/laravel/laravel/blob/develop/upgrade.md
If not then the Laravel package is not installing fully/at all.
Turns out the comment was the solution.
These commands should help:
composer remove doctrine/dbal will solve the problem.
composer remove packagename removes package.

Categories