Here's a basic template for a Declarative Schema XML file in Magento 2:
<?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="your_table_name_here" resource="default" engine="innodb" comment="Your Table Comment">
<column xsi:type="int" name="entity_id" padding="10" unsigned="true" nullable="false" comment="Entity ID" identity="true"/>
<column xsi:type="varchar" name="name" nullable="false" length="255" comment="Name"/>
<column xsi:type="text" name="description" nullable="true" comment="Description"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="entity_id"/>
</constraint>
</table>
</schema>
This template defines a basic schema for a table named your_table_name_here
. You should replace your_table_name_here
with the actual name of your table. You can then define columns within the <table>
element and specify their types, names, and other attributes. Additionally, you can define constraints like primary keys using the <constraint>
element.
Make sure to adjust the schema according to your specific requirements, including adding or removing columns and constraints as needed.
The db_schema_whitelist. json file is a way of telling Magento which tables and columns it can safely alter using the db_schema. xml file.
php bin/magento setup:db-declaration:generate-whitelist --module-name=VendorName_ModuleName