Declarative Schema in Magento 2

Did You know How to Use the Declarative Schema in Magento 2? Here is a Guide

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.

 

  1. Create a db_schema.xml File inside etc Directory

A table node can contain three types of subnodes:

  1. Column
  2. Constraint
  3. Index
Are your ready to migrate your store to Magento 2?

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.

 

Contributed By

Sharika Dubey

Leave a Reply

Your email address will not be published. Required fields are marked *

CommentLuv badge