Due to a migration, some products have a wrong (not existing) attribute group.

Is there a simple way to change this with a SQL query?

If yes, where can I see wich attribute-group is wich...

  • This is the 'error' i get in the reports: a:4:{i:0;s:48:"No such entity with attributeSetId = 31";i:1;s:9778:"#0 /home/...../domains/......./public_html/vendor/magento/module-eav/Model/Attribute/GroupRepository.php(116): Magento\Framework\Exception\NoSuchEntityException::singleField('attributeSetId', '31') ...... May 18, 2018 at 7:01

1 Answer 1


You can create setup script in custom module or run provided code in custom controller

namespace Vendorname\Modulename\Setup;

use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface;

class InstallData implements InstallDataInterface {

 * Installs data for a module
 * @param ModuleDataSetupInterface $setup
 * @param ModuleContextInterface $context
 * @return void
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');

    $collection = $productCollection->create()
    foreach ($collection as $product){
         $productData = $objectManager->create('\Magento\Catalog\Model\Product')->load($product->getId());
    $attributeSet = $objectManager->create('Magento\Eav\Api\AttributeSetRepositoryInterface');
    $attributeSetRepository = $attributeSet->set(/*your attribute set id*/); 
    $attributeSetRepository = $attributeSet->getAttributeSetName("attributeSetName");



  • Sorry for being a noob but how do i actually do that? I't for Magento 2 btw May 18, 2018 at 8:55
  • its for magento2 , you can use this script in any module or custom module or else you can create custom controller and execute it with code , just remove startsetup and endsetup from code May 18, 2018 at 12:10

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.