首页 > 解决方案 > Magento 2.3 无法在数据库表中设置默认值 NULL

问题描述

我想将新列添加到愿望清单表中,类型为整数,默认值为 NULL,但 magento 将其设置为“0”。这是我的 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="wishlist" resource="default" engine="innodb" comment="Wishlist main Table">
        <column xsi:type="int" name="new_column" padding="10" unsigned="true" nullable="true" identity="false"
                default="NULL" comment="Customer ID"/>
        <constraint xsi:type="foreign" referenceId="WISHLIST_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID" table="wishlist"
                    column="customer_id" referenceTable="customer_entity" referenceColumn="entity_id"
                    onDelete="CASCADE"/>
        <constraint xsi:type="unique" referenceId="WISHLIST_CUSTOMER_ID" disabled="true"/>
        <index referenceId="WISHLIST_CUSTOMER_ID" indexType="btree">
            <column name="customer_id"/>
        </index>
    </table>
</schema>

我可以在 phpmyadmin 中将默认值编辑为“NULL”,但我需要 Magento 自动执行此操作。提前致谢。

标签: magento2magento-2.3

解决方案


您是否执行过设置:升级?


推荐阅读