Rename a tablename using db_schema(Declarative schema) in Magento 2.

In Magento 2, You can create a new table using db_schema.xml file. After creating a table you want to rename a table name, You can rename a table using declarative schema.

New Table(mycustom_table) db_schema.xml file,

Now you must have to run generate-whitelist command to generate db_schema_whitelist.json file, Continue reading “Rename a tablename using db_schema(Declarative schema) in Magento 2.”

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

In Magento 2, You can create a new table using db_schema.xml file. The table contains many columns based on your requirements.

Check the blog for, How to creates a new database table.

In the future, if you want to remove or drop some column from an existing table you can simply drop a column using db_schema.xml file.

Let’s assume, You have created a table name, my_custom_table in the database with email column and you want to remove email column.

Table with a list of entry and some of the columns you don’t require, You can remove those columns using attribute disabled=true in a db_schema.xml file. Continue reading “Drop a column from the table using db_schema.xml in Magento 2.”

Create db_schema_whitelist.json file using CLI in Magento 2.

In Magento 2, From Magento Version 2.3 and higher version contains the declarative schema approach for InstallSchema/Upgrade schema, InstallData/Upgrade data functionality.

You can create db_schema_whitelist.json using Command line with a single command,

Generated file location is the <Vendorname>/<Modulename>/etc/db_schema_whitelist.json in your module. Continue reading “Create db_schema_whitelist.json file using CLI in Magento 2.”