SQLSTATE[42S22]: Column not found: 1054 Unknown column in Magento 2 is one of the most common errors that is displayed when a certain column is not found in the database. If you are a Magento 2 store owner getting this error during mass action in the admin grid, then this blog post is for you.
Many Magento 2 store admins complained about the mass action functionality not working properly in the backend grid. The following error is displayed in Magento 2 while performing bulk actions from the backend. The admin panel displays the following error:
.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column ” in ‘where clause’
I have come up with a working solution to the SQLSTATE[42S22] error in Magento 2 admin panel, which occurs while performing bulk actions. You can follow the steps provided in this blog post to solve it.
Let’s begin!
How to Solve SQLSTATE[42S22] Error in Magento 2 Admin Grid Mass Action?
The mentioned error is displayed while performing bulk actions in Magento 2 admin grid because the query does not find any primary key for the requested data in the store’s database. Therefore, the admin needs to define the $_idFieldName in the collection.php file in the backend first to set the primary key for the requested database. You can follow the below-mentioned steps to do that:
Step 1: Open the Collection.php file of the respective database. For example: Go to app\code\Vendor\Example\Model\ResourceModel\ExampleResourceClass\ directory and open the Collection.php file.
Step 2: Now define the $_idFieldName variable in the file with the column name of the primary key as the value. For example:
protected $_idFieldName = 'department_id';
That’s it! This is how you can solve the SQLSTATE[42S22] error in Magento 2 for performing mass action in the admin panel. Likewise solve SQLSTATE[42S22]: Column not found: 1054 Unknown column in Magento 2 admin grid massaction, it is one of the most common errors that is displayed when a certain column is not found in the database.
If you still have any doubts or queries regarding the provided solution, feel free to comment. I will be happy to help you! After done with this you can also learn to add image thumbnail column in Magento 2 admin UI grid.
Also, do not forget to share this Magento 2 solution with your developer friends via social media.
Thanks for reading.
Also Read: