Declaring Custom Database Tables in Magento 2 with db_schema.xml
Use Magento 2 declarative schema to add custom tables and columns without install scripts, plus how to whitelist removals and verify setup:upgrade.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Use Magento 2 declarative schema to add custom tables and columns without install scripts, plus how to whitelist removals and verify setup:upgrade.
A practical architecture note for Magento custom modules: use etc/db_schema.xml for DDL, idempotent data patches for DML, and setup:upgrade as the single deployment path.
Learn how Magento’s declarative schema lets you define database changes in XML, letting setup:upgrade generate the needed ALTER scripts automatically.
Step‑by‑step guide to add a database column using db_schema.xml, run setup:upgrade, verify the change, and recover if needed.
Magento's declarative schema in db_schema.xml defines a desired database state, but setup:upgrade does not provide a built-in command to undo an applied schema change. The platform intentionally retains tables even when they are removed from the XML, which prevents accidental data loss but also means reverting code alone cannot restore the previous schema. B