Tag Archives: Upgrade

Magento 2: setup upgrade error “We can’t find the role for the user you wanted”

open the file
vendor/magento/module-authorization/Model/Acl/AclRetriever.php and replaced the below code

if (!$role) {
throw new AuthorizationException(
__('We can\'t find the role for the user you wanted.')
);
}
$allowedResources = $this->getAllowedResourcesByRole($role->getId());

with

if (!$role) {
$allowedResources = array();
}

and revert it on sucess.

magento setup upgrade Unexpected error. Unable to create oAuth consumer account.

I have encountered this issue while community to enterprise migration and it was happening since the base table ‘oauth_consumer‘ was not available.

CREATE TABLE oauth_consumer (   entity_id int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id',
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created At',
updated_at timestamp NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP COMMENT 'Updated At',
name varchar(255) NOT NULL COMMENT 'Name of consumer',
key varchar(32) NOT NULL COMMENT 'Key code',
secret varchar(32) NOT NULL COMMENT 'Secret code',
callback_url text COMMENT 'Callback URL',
rejected_callback_url text NOT NULL COMMENT 'Rejected callback URL',
PRIMARY KEY (entity_id),
UNIQUE KEY OAUTH_CONSUMER_KEY (key),
UNIQUE KEY OAUTH_CONSUMER_SECRET (secret),
KEY OAUTH_CONSUMER_CREATED_AT (created_at),
KEY OAUTH_CONSUMER_UPDATED_AT (updated_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='OAuth Consumers';

Recurring Magento 2

Recurring script can be used to run some script that need to executed whenever we issue php bin/magento setup:upgrade irrespective of version change.

The recurring script will be run after the module setup script every time the command line

php bin/magento setup:upgrade

This script will be defined same as InstallSchema class but difference in name of the class. The example for this class you can see in vendor/magento/module-indexer/Setup/Recurring.php

InstallData Magento 2

The InstallData will be run during the module install and its used to load initial data to DB table.

The module install script will run when you run the following command line

php bin/magento setup:upgrade

File : app/code/PHPCodez/First/Setup/InstallData.php

<?php
 namespace PHPCodez\First\Setup;
 use Magento\Framework\Setup\InstallDataInterface;
 use Magento\Framework\Setup\ModuleContextInterface;
 use Magento\Framework\Setup\ModuleDataSetupInterface;
 class InstallData implements InstallDataInterface {
   public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) {
   $setup->startSetup();
   $setup->getConnection()->query("INSERT INTO phpcodez_post SET name = 'Post 1'");
   $setup->endSetup();
 }
 }