This solution worked for me.
ThiseavSetup->addAttribute(
solution worked for me. \Magento\Catalog\Model\Product::ENTITY,
eavSetup->addAttribute( \Magento\Catalog\Model\Product::ENTITY, 'test_demo221', [ 'type' => 'int', 'backend' => '', 'frontend' => '', 'label' => 'Test Attribute', 'input' => '', 'class' => '', 'source' => '', 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_GLOBAL, 'visible' => true, 'required' => false, 'user_defined' => false, 'default' => 0, 'searchable' => false, 'filterable' => false, 'comparable' => false, 'visible_on_front' => false, 'used_in_product_listing' => true, 'unique' => false, 'apply_to' => '' ] );
'test_demo221',
[
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Test Attribute',
'input' => '',
'class' => '',
'source' => '',
'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => 0,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => ''
]
);
$ATTRIBUTE_GROUP = 'General';
$attribute_set_id = '';
$attribute_set_name = 'ENTER ATTRIBUTE SET NAME HERE';
$attributeSetList = $this->getAttributeSetList($attribute_set_name);
foreach ($attributeSetList as $attributeSet) {
$attribute_set_id = $attributeSet['attribute_set_id'];
}
$entityTypeId = $eavSetup->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY);
$groupId = $eavSetup->getAttributeGroupId($entityTypeId, $attribute_set_id, $ATTRIBUTE_GROUP);
$eavSetup->addAttributeToGroup(
$entityTypeId,
$attribute_set_id,
$groupId,
'test_demo221', //attribute_code
null
);