We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    Magento 2.4 version have given feature to add table using declarative schema.

    Module name : Magemonkeys_Core

    We need to create db_schema.xml file in the app/code/Magemonkeys/Core/etc/  folder

    <?xml version="1.0" encoding="UTF-8"?>
    <schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
       <table name="customtable" resource="default" engine="innodb" comment="Custom table">
          <column xsi:type="smallint" name="id" unsigned="false" nullable="false" identity="true" comment="ID" />
          <column xsi:type="varchar" name="name" nullable="false" length="20" comment="Name" />
          <column xsi:type="varchar" name="email" nullable="false" length="20" comment="Email" />
          <constraint xsi:type="primary" referenceId="PRIMARY">
             <column name="id" />
          </constraint>
       </table>
    </schema>

    After that, we need to generate db white list schema json

    For that, we need to run command as per below

    php bin/magento setup:db-declaration:generate-whitelist --module-name=Magemonkeys_Core

    After that we need to run setup:upgrade and cache:flush command

    That’s it.

     

    Fill the below form if you need any Magento relate help/advise/consulting.

    With Only Agency that provides a 24/7 emergency support.

      Get a Free Quote