Loading...


Related Products


Date Published: February 6, 2025

Troubleshooting Drush error "Could not load SQL class."

Issue

When running a drush command or script that uses drush, you see errors that look like these:

Could not load SQL class. There is a mismatch between your Drupal root and your PHP autoloading.
This can happen if you mix Drupal 8 and Drupal 7.
Please check that the location of Drush matches the Drupal core version you want Drush to talk to.

Resolution

  • Ensure the composer package drush/drush so that it's present in the folder [Git repository root]/vendor/drush/drush
  • Ensure you have a symlink in [Git repository root]/vendor/bin/drush that points to ../drush/drush/drush
    • Note: Sometimes the vendor/bin folder does not exist and will need to be created first.

After this, you should now be able to run drush from the commandline, and it should pick up on the correct drush version.

Example steps to show and fix the error

NOTE: The below output shows steps done ONLY on a local development environment. To fix this on an Acquia environment, you would need to first create the symlink, then commit it to your code repository, and then push that code into your Acquia environment.

# Step 1: Test drush to show the error.
# Note: ~/Sites/localsite/mysite is the Git repository root.

~/Sites/localsite/mysite/vendor/bin (master)$ drush st 
Could not load SQL class. There is a mismatch between your Drupal root and your PHP autoloading.        [error]
This can happen if you mix Drupal 8 and Drupal 7.                                                       [error]
Please check that the location of Drush matches the Drupal core version you want Drush to talk to.      [error]
 Drupal version  :  8.9.6      
 Site URI :  http://default    
{ ... snip ... }

# Step 2: Verify if the vendor/bin/drush symlink exists
~/Sites/localsite/mysite/vendor/bin (master)$ ls -l drush
ls: cannot access 'drush': No such file or directory

# Step 3: Create the missing symlink
~/Sites/localsite/mysite/vendor/bin (master)$ ln -s ../drush/drush/drush drush

~/Sites/localsite/mysite/vendor/bin (master)$ ls -l drush
lrwxrwxrwx 1 myuser myuser 20 Aug  5 11:26 drush -> ../drush/drush/drush

# Step 4: Test again: error should be gone!
# NOTE: The "Drush script" line below should show the path to the Drush script in vendor/drush
~/Sites/localsite/mysite/vendor/bin (master)$ drush st
 Drupal version   : 8.9.6     
 Site URI  : http://default   
 DB driver : mysql     
 DB hostname : localhost        
 DB port   : 3306      
 DB username : root      
 DB name   : mydatabase      
 Database  : Connected        
{ ... snip ... }
 Drush script     : /home/myusername/Sites/localsite/mysite/vendor/drush/drush/drush

Did not find what you were looking for?

If this content did not answer your questions, try searching or contacting our support team for further assistance.

Back to Section navigation
Back to Site navigation