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: