I have created custom customer attribute. It is displaying in customer grid in admin panel but when I try to filter on my custom attribute, I get error
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'customer_attribute' in 'where clause'.
This is because it's not available in table customer_grid_flat I have already done re-indexing.
When I change value of is_used_in_grid to 1 from table customer_eav_attribute and start re indexing i am getting following error
PHP Fatal error: Uncaught Error: Call to undefined method Magento\Customer\Model\Indexer\Source::addAttributeToSelect() in /opt/lampp/htdocs/magento-221/vendor/magento/framework/Indexer/Handler/AttributeHandler.php:38
I have tried changing following column value to 1 but not working.
is_visible_in_grid is_filterable_in_grid is_searchable_in_grid Here is setup file code
use Magento\Eav\Model\Config; use Magento\Eav\Model\Entity\Setup\Context; use Magento\Eav\Setup\EavSetup; use Magento\Framework\App\CacheInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory; class CustomerSetup extends EavSetup { protected $eavConfig; public function __construct( ModuleDataSetupInterface $setup, Context $context, CacheInterface $cache, CollectionFactory $attrGroupCollectionFactory, Config $eavConfig ) { $this -> eavConfig = $eavConfig; parent :: __construct($setup, $context, $cache, $attrGroupCollectionFactory); } public function installAttributes($customerSetup) { $this -> installCustomerAttributes($customerSetup); $this -> installCustomerAddressAttributes($customerSetup); } public function installCustomerAttributes($customerSetup) { $customerSetup -> addAttribute(\Magento\Customer\Model\Customer::ENTITY, 'customer_approval', [ 'label' => 'Customer Approve', 'system' => 0, 'position' => 108, 'sort_order' =>108, 'visible' => false, 'note' => 'Customer Approval', 'type' => 'int', 'input' => 'boolean', 'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean', ] ); $customerSetup -> getEavConfig() -> getAttribute('customer', 'customer_approval')->setData('is_user_defined',1)->setData('is_required',0)->setData('default_value','')->setData('used_in_forms', ['adminhtml_customer', 'customer_account_create', 'customer_account_edit']) -> save(); } public function installCustomerAddressAttributes($customerSetup) { } public function getEavConfig() { return $this -> eavConfig; } Can anyone please let me know what is wrong with that.
addFieldToSelectinstead of addAttributeToSelect.addFieldToSelectused for flat modeladdAttributeToSelectuser for EAV model