Answer the question
In order to leave comments, you need to log in
Why is the column in the table not deleted when db_schema.xml is changed?
Described the table in a declarative schema (Magento 2.3):
app/code/Mi/DeclarativeSchema/etc/db_schema.xml
<?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="mi_declarative_schema_test" resource="default" comment="Declarative schema test">
<column xsi:type="int" name="id" identity="true" comment="ID Auto Increment" />
<column xsi:type="varchar" name="name" length="1024" nullable="false" comment="Name" />
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="id" />
</constraint>
</table>
</schema>
Answer the question
In order to leave comments, you need to log in
Try it like I did:
1) create a db_schema.xml file with the following structure:
<?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="mi_declarative_schema_new" resource="default" comment="Declarative schema test">
<column xsi:type="int" name="id" identity="true" comment="ID Auto Increment" />
<column xsi:type="text" name="name" comment="name" />
<column xsi:type="text" name="email" comment="email" />
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="id" />
</constraint>
</table>
</schema>
php bin/magento cache:flush
php bin/magento setup:db-declaration:generate-whitelist --module-name=Mi_DeclarativeSchema
php bin/magento setup:upgrade
<?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="mi_declarative_schema_new" resource="default" comment="Declarative schema test">
<column xsi:type="int" name="id" identity="true" comment="ID Auto Increment" />
<column xsi:type="text" name="name" comment="name" />
<!--<column xsi:type="text" name="email" comment="email" />-->
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="id" />
</constraint>
</table>
php bin/magento setup:db-declaration:generate-whitelist --module-name=Mi_DeclarativeSchema
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question