2

I tried to upgrade from 2.4.6 to 2.4.8. After upgrading when i exec php bin/magento setup:upgrade -vvv

I have this error

Warning: Undefined array key "type" in /vendor/magento/framework/Setup/Declaration/Schema/Db/SchemaBuilder.php on line 90

I cannot find the module with error in db_schema.xml

2 Answers 2

2

This error occurs when a table column is declared in the db_schema.xml file without specifying the required attribute: the column type (xsi:type). Magento 2.4.8, along with 2.4.7-p5, expects this attribute to properly interpret and generate the database schema.

Example of incorrect declaration
In the example below, the column is defined without specifying the type (xsi:type), which causes the error:

<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="your_table_name" resource="default" engine="innodb" comment="Table Comment">
        <!-- additional declaration -->
        <column name="code" nullable="true" length="32" comment="Code"/>
    </table>
</schema>

Correct declaration with xsi:type
To resolve this issue, ensure that the xsi:type attribute is properly defined for each column. In the case of a varchar column, the correct declaration would look like this:

<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="your_table_name" resource="default" engine="innodb" comment="Table Comment">
        <!-- additional declaration -->
        <column xsi:type="varchar" name="code" nullable="true" length="32" comment="Code"/>
    </table>
</schema>

For tables that are defined without columns and marked with disabled="true"

<table name="test_table" resource="default" engine="innodb" comment="Table" disabled="true">
</table>

How to troubleshoot and Identify the Issue
If you are encountering this error and want to track down which columns or tables are affected, you can modify the vendor/magento/framework/Setup/Declaration/Schema/Db/SchemaBuilder.php file for more detailed error reporting. By adding additional error handling, you can pinpoint the table and column where the issue occurs.

Original code:

if ($columnData['type'] == 'json') {
    $tablesWithJsonTypeField[$keyTable] = $keyColumn;
}

Replace with:

try {
    if ($columnData['type'] == 'json') {
        $tablesWithJsonTypeField[$keyTable] = $keyColumn;
    }
} catch (\Throwable $e) {
    // Create a new exception with extended context message
    $errorMessage = sprintf(
        "%s\nError processing table %s column %s",
        $e->getMessage(),
        $keyTable,
        $keyColumn
    );

    // Throw a new exception with the extended message
    // This preserves the original error but adds our context
    throw new \Exception($errorMessage, $e->getCode(), $e);
}

More resources:

0

Looks like one of the custom modules dbschema.xml file missing "type" attribute with one of the columns definition. Here is how you can troubleshoot and resolve this issue:

  1. Check the db_schema.xml files in all custom and third-party modules. Look for any column definitions that might be missing the type attribute.

  2. Run the command with debugging enabled: php bin/magento setup:upgrade -vvv. This might give you more context about which module or file is causing the issue.

  3. Ensure that all db_schema.xml files follow Magento's schema declaration standards. Every column should have a type attribute defined.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.