How to add new tables for a custom module in Magento 2
Hi Everybody, I am Cuong, Welcome to my Magento 2 Tutorial video series.
Today, I am going to show everybody a best practice, How to add new tables for a custom module in Magento 2.
In the previous video, I showed everyone How to create a new module in Magento 2, I created a new module called PHPCuong_BannerSlider. You can see that practice at the link
In this video, I will add two new tables to this module.
You can see the structure of these tables at the link
The table named stores has already existed in the database.
To complete this best practice you need to complete the following high-level steps:
1. Create the file named InstallSchema.php in the path appcodePHPCuongSetup
2. Generate the new tables
Run the command line:
– php bin/magento setup:upgrade –keep-generated
If your module has already installed before, you need to delete it in the table named setup_module, then run the command above again
3. Check the results
Go to the database, get a look at the tables named phpcuong_banners_slider, phpcuong_banners_slider_group
It works great!. In the next video, I will show everyone, How to display the banners slider in the Grid in the backend.
Thank you for your watching. If you have any questions about this exercise please feel free to leave a comment below.
Don’t forget to like, comment, share and subscribe to my channel for getting the latest videos.
Please do not hesitate to contact me if you need me to join your Magento project. My rate is $25/hour in Magento 1 and $30/hour in Magento 2.
Get the source codes of this tutorial on the github
See more here