Did You know How to Use the Declarative Schema in Magento 2? Here is a Guide
Magento includes this feature in its 2.3 version. It simplifies the Magento’s installation and upgrade processes. Previously we had to write the database script for each version of the module. Various scripts were required for different operations on the database.
Declarative schema helps Magento to simplify module upgradation procedures. Natively each upgrade scripts iteratively adds changes to database blindly. Declarative Schema setup is based on database structure declarations.
Declarative Schema files declare what the database structure should be, and Magento determines the differences between the current table structure and what it should be.
Here, I will tell you how easily you can create a table using the declarative schema.
- Create a db_schema.xml File inside etc Directory
A table node can contain three types of subnodes:
But before Running the Upgrade Command, You Need to Add Your Schema to db_schema_whitelist.json File by Running the Following Command-
php bin/magento setup:db-declaration:generate-whitelist –module-name=Ids_DeclarativeTest
it will be look like this.
When you will run s:up command table will be created.
Hope this will help someone.