Magento 2 – Difference Between InstallSchema and InstallData

databaseinstalldatamagento2

I want to know the difference between InstallSchema and InstallData in details.

I also need to know when can I use InstallSchema.php and InstallData.php?

Best Answer

First both InstallSchema And InstallData both method are called when you install any new module

Schema setup scripts change database schema, they create or change needed database tables. If module is installing, Setup\InstallSchema::install() is executed.

It means it create new table and its fields with its structure.

InstallData setup scripts contain entries module needs to insert into database. Attributes that come with Magento by default,Cms pages, various default groups and roles, are all examples of data setup.

Data setup is executed after Schema setup, they function in a similar fashion.

So come to the conclustion, Main difference between both is InstallSchema is used to make table and its structure. While InstallData is used to insert/add data into table.

Related Topic