0

I wanted to see if there is a way to change a user role using drush. I found this post explaining how to do it but I get an error. I replaced the actual username with "USERNAME".

drush user-add-role administrator USERNAME

> exception 'Drush\Role\RoleException' with message 'Could not find the
> role:      [error] administrator' in
> /usr/local/src/drush/lib/Drush/Role/RoleBase.php:46 Stack trace:
> #0 [internal function]: Drush\Role\RoleBase->__construct('administrator')
> #1 /usr/local/src/drush/includes/drush.inc(113): ReflectionClass->newInstanceArgs(Array)
> #2 /usr/local/src/drush/commands/core/role.drush.inc(273): drush_get_class('Drush\\Role\\Role', Array)
> #3 /usr/local/src/drush/commands/user/user.drush.inc(281): drush_role_get_class('administrator')
> #4 [internal function]: drush_user_add_role('administrator', 'USERNAME')
> #5 /usr/local/src/drush/includes/command.inc(368): call_user_func_array('drush_user_add_...', Array)
> #6 /usr/local/src/drush/includes/command.inc(219): _drush_invoke_hooks(Array, Array)
> #7 [internal function]: drush_command('administrator', 'USERNAME')
> #8 /usr/local/src/drush/includes/command.inc(187): call_user_func_array('drush_command', Array)
> #9 /usr/local/src/drush/lib/Drush/Boot/BaseBoot.php(62): drush_dispatch(Array)
> #10 /usr/local/src/drush/drush.php(70): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
> #11 /usr/local/src/drush/drush.php(11): drush_main()
> #12 {main}

I am using Drupal Commons 7.50 and Drush 7.0.0.

Edit: Things I have tried:

  • spelling role correctly and making sure it exists
  • clearing cache
6
  • 3
    Probably a stupid question but does the site definitely have an "administrator" role? Have you double-checked the UI/database to be sure?
    – Clive
    Jan 19, 2017 at 17:48
  • Not a stupid question. Apparently we had the role named "administrators". Awesome, thanks!
    – Christia
    Jan 19, 2017 at 17:49
  • Changed the command to administrators but still get the same error.
    – Christia
    Jan 19, 2017 at 17:50
  • Well that's some sort of progress I guess :) Try clearing the cache just in case
    – Clive
    Jan 19, 2017 at 17:51
  • No such luck. I edited my answer to reflect things things tried.
    – Christia
    Jan 19, 2017 at 18:02

1 Answer 1

1

Syntax was wrong. It needed quotes and capitalization definitely matters.

drush user-add-role "administrator" USERNAME

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.