Clever works_

How to create a custom table in Magento 2

Magento 2 Create A Custom Table

Today we will create a custom table in Magento 2 to our HelloWorld Module. If you need to carry information instead of attributes, this is a good choice for you. Firstly we need to create a file called InstallSchema.php in app/code/CleverCode/HelloWorld/Setup with the following contents:

Scripts called InstallSchema.php or InstallData.php run when the module is first installed. Our class needs to implement InstallSchemaInterface. Because our module is installed, we need to remove information about module installation from setup_module table via phpMyAdmin or by using raw SQL:

The scripts add two columns one called id and other called name. After that we need to type:

When we refresh any Magento page, we will see a new table in database called hello.

Related works_

BreakAwayDistributing B2B and B2C
selling platform

The SLK Solutions agency responsible for developing an online store hired us to help them with creating a selling platform dedicated to B2B and B2C clients. BreakAwayDistributing – agency operating from 1993 with main office located in Hamilton, Canada offers high quality products

Learn more

Internet flower shop
from SLK Solutions

SLK Solutions is an IT agency operating in the USA, which helps small and large business owners to implement new technologies. They asked us to support them with our experts with the complete implementation of an eCommerce project for their client.

Learn more