Create Tabel In Magento 2

Prerequisite for follow this tutorial [optional]

I already created a boilerplate module, which makes easy to follow this tutorial. It is optional, you can follow with your own module too.

  1. Download module repository from bitbucket
  2. Extract downloaded folder
  3. Copy Bilal folder into your <magento-root>/app/code/

After run the below commands to enable module

Once you’ve run the above, you should be able to access the following URL in your system

and see the rendered text

Create Table

Whenever you want to create new table, you should write create table logic in InstallSchema.php

Bilal/Cruddemo/Setup/InstallSchema.php

Delete record of the cruddemo module from the setup_module table.

InstallSchema.php only execute while run setup upgrade, while setup upgrade Magento look into setup_module table, whether the extension new or exist, if exist, it skips the InstallSchema execution that’s why we delete the records, now Magento think “it is new module so we need to execute InstallSchema.php”

run the below command

That’s it!

Check the database, we have our newly created table.

Please carry same source code to follow the next tutorial.

About Bilal

I'm a software programmer, I handle Magento2 modifications at any level.

View all posts by Bilal →

2 Comments on “Create Tabel In Magento 2”

Leave a Reply

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