Magento – Errors on Declarative Schema on custom module on 2.3

magento2magento2.3

My module was implemented and working on Magento 2.2.

We are moving to Magento 2.3, but failed in Declarative Schema.

I follow this. Created db_schema.xml. Following is the example

    <schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">

   <table name="options" resource="default" engine="innodb" comment="Option entities">
        <column xsi:type="int" name="option_id" padding="10" unsigned="true" identity="true" nullable="false" comment="Option Id"/>
        <column xsi:type="varchar" name="name" nullable="false" length="255" comment="Option name"/>
        <column xsi:type="varchar" name="value" nullable="false" length="255" comment="Option value"/>
        <column xsi:type="timestamp" name="created" comment="Time of event"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="option_id"/>
        </constraint>
    </table>
</schema>

Then, whatever commands I tried to run returns the same error..

PHP Fatal error:  Uncaught TypeError: Return value of Magento\Framework\Setup\Declaration\Schema\Declaration\SchemaBuilder::processTable() must be an instance of Magento\Framework\Setup\Declaration\Schema\Dto\Table, boolean returned in C:\xampp\htdocs\magento23\vendor\magento\framework\Setup\Declaration\Schema\Declaration\SchemaBuilder.php:251
Stack trace:
#0 C:\xampp\htdocs\magento23\vendor\magento\framework\Setup\Declaration\Schema\Declaration\SchemaBuilder.php(148): Magento\Framework\Setup\Declaration\Schema\Declaration\SchemaBuilder->processTable(Object(Magento\Framework\Setup\Declaration\Schema\Dto\Schema), Array)
#1 C:\xampp\htdocs\magento23\vendor\magento\framework\Setup\Declaration\Schema\SchemaConfig.php(78): Magento\Framework\Setup\Declaration\Schema\Declaration\SchemaBuilder->build(Object(Magento\Framework\Setup\Declaration\Schema\Dto\Schema))
#2 C:\xampp\htdocs\magento23\setup\src\Magento\Setup\Model\DeclarationInstaller.php(57): Magento\Framework\Setup\Declaration\Schema\SchemaConfig->getDeclarationConfig()
#3 C:\ in C:\xampp\htdocs\magento23\vendor\magento\framework\Setup\Declaration\Schema\Declaration\SchemaBuilder.php on line 251

Fatal error: Uncaught TypeError: Return value of Magento\Framework\Setup\Declaration\Schema\Declaration\SchemaBuilder::processTable() must be an instance of Magento\Framework\Setup\Declaration\Schema\Dto\Table, boolean returned in C:\xampp\htdocs\magento23\vendor\magento\framework\Setup\Declaration\Schema\Declaration\SchemaBuilder.php:251
Stack trace:
#0 C:\xampp\htdocs\magento23\vendor\magento\framework\Setup\Declaration\Schema\Declaration\SchemaBuilder.php(148): Magento\Framework\Setup\Declaration\Schema\Declaration\SchemaBuilder->processTable(Object(Magento\Framework\Setup\Declaration\Schema\Dto\Schema), Array)
#1 C:\xampp\htdocs\magento23\vendor\magento\framework\Setup\Declaration\Schema\SchemaConfig.php(78): Magento\Framework\Setup\Declaration\Schema\Declaration\SchemaBuilder->build(Object(Magento\Framework\Setup\Declaration\Schema\Dto\Schema))
#2 C:\xampp\htdocs\magento23\setup\src\Magento\Setup\Model\DeclarationInstaller.php(57): Magento\Framework\Setup\Declaration\Schema\SchemaConfig->getDeclarationConfig()
#3 C:\ in C:\xampp\htdocs\magento23\vendor\magento\framework\Setup\Declaration\Schema\Declaration\SchemaBuilder.php on line 251

Commands which produces the above error:

bin/magento setup:db-declaration:generate-whitelist   
bin/magento module:upgrade

I tried to install the module on a fresh installed Magento 2.3

Can anyone please help?

Best Answer

I had the exact same issue and discovered it was caused in a custom module. The problem was that setAreaCode() was called in the constructor. I relocated setAreaCode() into the execute() method and the issue was fixed.

Related Topic