Hello magento friends, Here we are explane that How does Magento 2.3's declarative schema work to build new database tables?
Starting with Magento 2.3, utilise the db schema.xml file rather than the InstallSchema PHP class to build new database tables. Declarative schema is the name of the new database table creation/updating concept in Magento 2.3.
➤ You no longer need to develop InstallSchema.php and UpgradeSchema.php as of Magento 2.3.
➤ By producing a DB schema XML file, you can now use a new method to build database tables.
➤ The db schema.xml file is located in the following directory:
app/code/"Packagename"/"Modulename"/etc.
➤ The XML code below can be used to construct your own custom table.
➤ I used a variety of different field types to create the new database table. You can make a database table with the lone necessary field.
- <table>…</table> : This tag is Used for create table in Magento 2.3+
- <column>…</column> : This tag is Used for create different column of the table
- You can set int, text, varchar, timestamp, date, datetime, smallint, float, decimal, double etc.
- <constraint>…</constraint> :This tag is Used for set of constraint, Like primary key, foreign key, unique key.
➤ You can set primary key usig constraint tag in db_schema:
where name is the column tag's primary key field.
To create or edit a table in Magento 2.3, use the Magento 2 Upgrade command.
Magento setup:upgrade in PHP
Using the db schema.xml file, you can now verify whether a new table will be created in a database.