How To

How to Fix Invalid Column Data Type when Reindex Magento 2

Hello Magento Friends,

In this blog, I am going to provide a solution to Fix Invalid Column Data Type when Reindex Magento 2.

Reindexing is required when the store data changes to increase the performance of the Magento 2 storefront. You can perform reindex through the command line or reindex programmatically in Magento 2.

But sometimes the reindex command throws an error of invalid column data type as shown in the below image

Let’s see How to Fix Invalid Column Data Type when Reindex Magento 2

Steps to Fix Invalid Column Data Type when Reindex Magento 2:

Step 1: Go to the below path

vendor/magento/module-eav/Model/ResourceModel/Helper.php

Insert the following lines into getDdlTypeByColumnType() function

   case 'int unsigned':
                $columnType = 'int';
                break;
            case 'smallint unsigned':
                $columnType = 'smallint';
                break;
            case 'bigint unsigned':
                 $columnType = 'bigint';
                 break;

So the getDdlTypeByColumnType() function before looked like this

public function getDdlTypeByColumnType($columnType)
{
    switch ($columnType)
    {
        case 'char':
        case 'varchar':
            $columnType = 'text';
            break;
        case 'tinyint':
            $columnType = 'smallint';
            break;
        default:
            break;
    }
    return array_search($columnType, $this->_ddlColumnTypes);
}

And now the getDdlTypeByColumnType() function has changed as below

public function getDdlTypeByColumnType($columnType)
{
     switch ($columnType)
     {
            case 'int unsigned':
                $columnType = 'int';
                break;
            case 'smallint unsigned':
                $columnType = 'smallint';
                break;
            case 'bigint unsigned':
                 $columnType = 'bigint';
                 break;
            case 'char':
            case 'varchar':
                $columnType = 'text';
                break;
            case 'tinyint':
                $columnType = 'smallint';
                break;
            default:
                break;
     }
     return array_search($columnType, $this->_ddlColumnTypes);
}

Conclusion:

Hence, this way you can get rid of Invalid Column Data Type while Reindexing in Magento 2. Additionally, if you face an error like “index is locked by another reindex process. Skipping.” while reindexing in Magento 2, you can easily solve it – Check the steps

Eliminate running the reindex command every time, instead perform reindexing with just a one-click from the admin dashboard. Integrate Magento 2 Admin Reindex Plugin.

Happy Coding!

Click to rate this post!
[Total: 2 Average: 5]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate ?️ Certified Magento Developer?‍?. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.?

Recent Posts

Improving Error Handling and Transition Management in Remix with useRouteError and useViewTransitionState

In modern web development, seamless navigation and state management are crucial for delivering a smooth…

6 days ago

Magento Open Source 2.4.8-Beta Release Notes

Magento Open Source 2.4.8 beta version released on October  8, 2024. The latest release of…

1 week ago

How to Create Catalog Price Rule in Magento 2 Programmatically?

Hello Magento Friends, Creating catalog price rules programmatically in Magento 2 can be a valuable…

1 week ago

Top 10 Tips to Hire Shopify Developers

As the world of eCommerce continues to thrive, Shopify has become one of the most…

2 weeks ago

Managing Browser Events and Navigation in Shopify Remix: useBeforeUnload, useHref, and useLocation Hooks

Shopify Remix is an innovative framework that provides a streamlined experience for building fast, dynamic,…

2 weeks ago

Ultimate Guide to Hiring a Top Shopify Development Agency

Building a successful eCommerce store requires expertise, and for many businesses, Shopify has become the…

2 weeks ago