719-286-0751 info@cadence-labs.com

Magento 2.3 / WordPress – Fix Cannot process definition to array for type tinytext

The Problem

So, you’ve upgraded your Magento 2.1 or 2.2 instance to the latest version of 2.3 (congrats!). You go to run:


php bin/magento setup:upgrade

and receive an error like the below:

Cannot process definition to array for type tinytext

Upon some investigation, you determine that Magento is complaining about a column in one of the WordPress tables in the same database…you read that right, Magento is complaining about the database table structure of another platform!

Note, to verify which column Magento is complaining about when this error is thrown, click here and read the first answer.

The truth is that this error can arise for tables related to Magento as well.

Some Background

This problem relates to some of the changes Magento made in 2.3 related to their declarative schema. In summary, this feature allows you to define database tables via an XML file (as opposed to a schema patch or setup script). Magento’s new declarative schema does not support the below types:

  • TINYTEXT
  • ENUM
  • TIME
  • MEDIUMINT

If a column from a table within the Magento 2 database has one of these data types, the correct way to resolve it is by manually changing the table structure to a supported data type. For example, changing TINYTEXT to VARCHAR.

But What About WordPress?

However, Magento should not demand you change table structures on another platform. Magento’s declarative schema validator is developed with regard to other platforms that may be installed in the same database. So obviously one fix is to move WordPress into its own database. However, for a variety of reasons, you may want to keep WordPress in the same database.

The Fix

To prevent Magento from complaining about WordPress tables, we’re going to create a simple composer patch to modify one of Magento’s core files. If you’re not familiar with composer patches, click here to learn more about them. Our tutorial will walk you through setting this up as well:

(1) Install Composer Patches:

Run the below bash command to add composer patches to your project – this is needed to apply the patch we are creating.


composer require cweagans/composer-patches

You will then need to update your composer.json with the below new section:


"extra": {
    "composer-exit-on-patch-failure": true,
    "patches": {
        // your patches go here...
    }
}

(2) Add the patch file to the codebase

In this section we will add a diff to modify the core Magento file:

vendor/magento/framework/Setup/Declaration/Schema/Db/MySQL/DbSchemaReader.php

  1. Create a folder at: MAGENTO_ROOT/patches/composer
  2. And add the file: MAGENTO_ROOT/patches/composer/DbSchemaReader_2.3_WP.patch
  3. With the below content:

diff --git a/vendor/magento/framework/Setup/Declaration/Schema/Db/MySQL/DbSchemaReader.php b/vendor/magento/framework/Setup/Declaration/Schema/Db/MySQL/DbSchemaReader.php
index 1a57911d8..05e49e89e 100644
--- a/vendor/magento/framework/Setup/Declaration/Schema/Db/MySQL/DbSchemaReader.php
+++ b/vendor/magento/framework/Setup/Declaration/Schema/Db/MySQL/DbSchemaReader.php
@@ -222,7 +222,8 @@ class DbSchemaReader implements DbSchemaReaderInterface
                 ['TABLE_NAME']
             )
             ->where('TABLE_SCHEMA = ?', $dbName)
-            ->where('TABLE_TYPE = ?', self::MYSQL_TABLE_TYPE);
+            ->where('TABLE_TYPE = ?', self::MYSQL_TABLE_TYPE)
+            ->where('TABLE_NAME NOT LIKE "wp_%"');
         return $adapter->fetchCol($stmt);
     }
 }

You’ll notice that we are modifying the Magento 2.3 declarative schema database validator to ignore all tables starting with “wp_” – this will exclude all WordPress tables. If your WordPress installation uses a different table prefix, you’ll need to alter the above code.

(3) Add Our composer patch entry to composer.json

Expand on the composer.json update from section 1 so it looks like the below:


"extra": {
    "composer-exit-on-patch-failure": true,
    "patches": {
        "DB Schema Reader Ignore WP Tables": "patches/composer/DbSchemaReader_2.3_WP.patch"
    }
}

(4) Apply The Patch

Run the below commands to apply the patch:


composer install && composer update --lock

Conclusion

After the above updates, you should be able to run:


php bin/magento setup:upgrade

without any problems. If you are still receiving the above warning, verify the patch is installed, and then follow the debugging instructions at the top of the article to determine if the offending column is actually coming from WordPress.

Alan Barber is the Lead Web Developer at Cadence Labs and a Magento 2 Certified Professional Developer.

Need help with Magento 2?

We’ve had a lot of experience building websites in Magento 2. If you need help, head over to the Cadence Labs contact page, or email us at info@cadence-labs.com

Submit a Comment

Your email address will not be published. Required fields are marked *

Install our webapp on your iPhone! Tap and then Add to homescreen.
Share This