I'm trying to write a drush command for a module and getting this error even though the module in question is enabled.

Here's my output:

$ drush field-tools-clone foobar foo bar --debug

Warning: Module 'pdo_mysql' already loaded in Unknown on line 0
Bootstrap to phase 0. [0.01 sec, 4.5 MB] [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drush() [0.01 sec, 4.76 MB] [bootstrap]
Loading drushrc "/Users/joachim/Sites/_sandbox/drush/drushrc.php" into "drush" scope. [0.01 sec, 4.77 [bootstrap]
MB]
Include /Users/joachim/Library/Drush [0.02 sec, 4.78 MB] [notice]
Cache HIT cid: 6.0-dev-commandfiles-0-4f23bb0e449e8457facd4296a84bdfd3 [0.02 sec, 4.79 MB] [debug]
Bootstrap to phase 0. [0.07 sec, 10.33 MB] [bootstrap]
Bootstrap to phase 5. [0.09 sec, 10.33 MB] [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_root() [0.1 sec, 10.33 MB] [bootstrap]
Initialized Drupal 7.14 root directory at /Users/joachim/Sites/mysite [0.12 sec, 14 MB] [notice]
Drush bootstrap phase : _drush_bootstrap_drupal_site() [0.12 sec, 14 MB] [bootstrap]
Initialized Drupal site default at sites/default [0.13 sec, 14.01 MB] [notice]
Cache HIT cid: 6.0-dev-commandfiles-2-c32acd775c18a90c5b41d0fc9accf5ab [0.13 sec, 14.01 MB] [debug]
Drush bootstrap phase : _drush_bootstrap_drupal_configuration() [0.13 sec, 14.01 MB] [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_database() [0.16 sec, 17.09 MB] [bootstrap]
Successfully connected to the Drupal database. [0.16 sec, 17.09 MB] [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_full() [0.16 sec, 17.09 MB] [bootstrap]
Cache HIT cid: 6.0-dev-commandfiles-5-4f2ed1ff17e7bc82af6797efd2a4cb05 [0.7 sec, 57.99 MB] [debug]
Cache HIT cid: 6.0-dev-commandfiles-2-1c82782e4f0daa661b06df029df9c6f1 [0.96 sec, 60.87 MB] [debug]
Command field-tools-clone needs the following module(s) enabled to run: field_tools. [1.01 sec, 61.26 [error]
MB]
The drush command 'field-tools-clone foobar foo bar' could not be executed. [1.01 sec, 61.26 MB] [error]

I've checked that this is not due to #1493022: improve readme and add "have command line use same php as webserver" for hint for "needs a higher bootstrap level to run" error -- the warning about pdo_mysql has started appearing now that I've copied my MAMP php.ini to ~/.drush/php.ini.

Here's my status output:

$ drush status

Warning: Module 'pdo_mysql' already loaded in Unknown on line 0
 Drupal version                :  7.14                                                        
 Site URI                      :  http://default                                              
 Database driver               :  mysql                                                       
 Database hostname             :  localhost                                                   
 Database username             :  drupal                                                      
 Database name                 :  drupal-mysite                                              
 Database                      :  Connected                                                   
 Drupal bootstrap              :  Successful                                                  
 Drupal user                   :  Anonymous                                                   
 Default theme                 :  bartik                                                      
 Administration theme          :  garland                                                     
 PHP configuration             :  /Users/joachim/.drush/php.ini /Users/joachim/.drush/php.ini 
 Drush version                 :  6.0-dev                                                     
 Drush configuration           :  /Users/joachim/Sites/_sandbox/drush/drushrc.php             
 Drupal root                   :  /Users/joachim/Sites/mysite                         
 Site path                     :  sites/default                                               
 File directory path           :  sites/default/files                                         
 Private file directory path   :  sites/default/files/private                                 
 temp                          :  /Applications/MAMP/tmp/php                                  

Comments

joachim’s picture

OK the problem seems to be that the cache needed clearing.

If drush finds a command is missing from the cache, could it perhaps do a clear of its cache itself?

jonhattan’s picture

Component: User Commands » Base system (internal API)
Status: Active » Postponed (maintainer needs more info)

If a command is missing from the cache drush will ask you to clear the cache. But it doesn't seem to be the problem here as the command was already found.

I think the «Command field-tools-clone needs the following module(s) enabled to run: field_tools.» error could be raised under other circumstances (see drush.php).

@joachim can you enum the steps to reproduce this?

seanr’s picture

I just encountered this - no idea why it happened, but drush cc drush as indicated above fixed it. This was on my local machine (OSX Lion) and a site I've been working with quite a bit over the last few weeks.

userofdrupal’s picture

drush cc also fixed the issue for me.

pjcdawkins’s picture

Title: "Command needs the following module(s) enabled to run" error when modules are enabled » "Command needs the following module(s) enabled to run" error
Status: Postponed (maintainer needs more info) » Active

If a command is missing from the cache drush will ask you to clear the cache.

And that's the bug, isn't it?

I run "drush elysia-cron" from crontab, and because of this drush behaviour, cron didn't run for several hours, and that meant a scheduled article failed to publish at the right time (which is embarrassing!). My workaround for now is to run "drush cc drush" in another cron job, slightly less often.

It doesn't just happen when modules are enabled/disabled - it appears to happen after other commands such as updatedb.

mikran’s picture

Version: » 7.x-5.8

I've just encountered this as well. I updated Drush to latest version and performed cc all afterwards but I found out the hard way that you need to do cc with each user separately.

$ drush vde
All arguments are required.
$ sudo drush vde
Command vde needs the following module(s) enabled to run: views_data_export.           [error]
The drush command 'vde' could not be executed.                                         [error]
broon’s picture

@mikran: Your sudo line actually pointed me to a solution for my problem where I wasn't able to get a drush command to run (see #1953246: Command fieldcopy needs the following module(s) enabled to run: field. for details of my specific problem). Short version in case someone stumbles upon the same issue:

The drush error message:

# drush fieldcopy field_image field_master_image story node
Command fieldcopy needs the following module(s) enabled to run: field. [error]
The drush command 'fieldcopy field_image field_main_image story node' could not be executed. [error]
# drush en field
field is already enabled. [ok]
There were no extensions that could be enabled.

Instead of
drush fieldcopy field_image field_main_image story node
I had to run
sudo drush --include=./sites/all/modules/field_value_copy/ fieldcopy field_image field_main_image story node

Environment: OSX 10.7.5, drush 5.8

geerlingguy’s picture

I just ran into the problem as well. $ drush cc drush fixed it.

pjcdawkins’s picture

Right, but that's a band-aid, not a cure.

greg.1.anderson’s picture

Version: 7.x-5.8 » 8.x-6.x-dev
Status: Active » Closed (won't fix)
Issue tags: +Needs migration

This issue was marked closed (won't fix) because Drush has moved to Github.

If desired, you may copy this bug to our Github project and then post a link here to the new issue. Please also change the status of this issue to closed (duplicate).

Please ask support questions on Drupal Answers.

joachim’s picture

Status: Closed (won't fix) » Closed (duplicate)
joachim’s picture

Issue summary: View changes

added debug

rahulbaisanemca’s picture

drush cc all solved my problem

Thanks.