Drop a column from the table using db_schema.xml in Magento 2

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.

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.

At last, we will upgrade the schema.

Voilà, We have dropped a column using db_schema.xml.

Leave a Reply