Magento 2 – Why Table Column Not Deleted After Changing db_schema.xml?

magento2magento2.3

I described the table with declarative schema (Magento 2.3):

<?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="mi_declarative_schema_test" resource="default" comment="Declarative schema test">
        <column xsi:type="int" name="id" identity="true" comment="ID Auto Increment" />
        <column xsi:type="varchar" name="name" length="1024" nullable="false" comment="Name" />
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="id" />
        </constraint>
    </table>
</schema>

I did setup:upgrade, the table was created, everything is ok. I add the columns,do an upgrade – they are added ok. But when I delete columns from xml, they are not deleted from the table. The instruction
https://devdocs.magento.com/guides/v2.3/extension-dev-guide/declarative-schema/db-schema.html says it is enough to delete or comment out the column line.
Magento connects to the DB with root access

Best Answer

I have added delete column sample code for name column. Magento added delete column for disabled="true" .

<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="mi_declarative_schema_test" resource="default" comment="Declarative schema test">
    <column xsi:type="int" name="id" identity="true" comment="ID Auto Increment" />
    <column xsi:type="varchar" name="name" length="1024" nullable="false" comment="Name" disabled="true"/>
    <constraint xsi:type="primary" referenceId="PRIMARY">
        <column name="id" />
    </constraint>
</table>
</schema>