Well, now in Magento 2 one can create a table using db_schema.xml if you want to drop column(s) using the same approach. You landed on the right page.
Drop column using attribute disabled=”true” in db_schema.xml.
Let’s take an example. Suppose in one of my custom tables, I have a column with the name cart_name which wanted to drop.
1 |
<column xsi:type='varchar' name='cart_name' nullable='true' length='255' comment='Cart name' disabled='true'/> |
Don’t much cheer, only disabled=’true’ will not work, we need to run commands for it.
It is mandatory to generate db_schema_whitelist.json.
Using below command we can generate db_schema_whitelist.json for our module only.
1 |
php bin/magento setup:db-declaration:generate-whitelist –module-name=My_ModuleName |
At last, we will upgrade the schema.
1 |
php bin/magento setup:upgrade |
Voilà, We have dropped a column using db_schema.xml.