Solved: SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column in Magento 2 Admin Grid MassAction
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:
1 |
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:
- Solved: Magento 2 Backend Not Working
- Debug: SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column in ‘where clause’ in Magento 2
- Solved: Argument Passed Must Be Array, Null Given Error in Magento 2 Admin Grid
Siddharth Nandava
Siddharth Nandava is an enthusiastic Jr Magento developer at Meetanshi. Apart from the work, you can find him learning new things and spending quality time with his family.
Prev
New Magento 2 Extensions & Updates [June 2022]
Solved: Admin Menu Not Working After Upgrading to Magento 2.4.4
Next