Magento 2 – Create database table

  1. Create an Vendor/Extension/etc/db_schema.xml file.
<?xml version="1.0" ?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">

    <table name="example_table">
        <column xsi:type="int" name="entity_id" padding="10" unsigned="true" nullable="false" comment="Entity Id"/>
        <column xsi:type="varchar" name="column_name" nullable="false" length="255"
                comment="Column Name"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="entity_id"/>
        </constraint>
    </table>

</schema>

 

Gareth
Buy Me A Coffee
back arrowBack to Index