0

我无法更新升级架构文件。

我想使用我已经更新的升级模式文件来更新数据库。

在我的模块中,我有一个使用安装模式文件创建的数据库表。

这是我的 UpgradeSchema 文件

<?php
namespace Mageplaza\HelloWorld\Setup;

use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;

class UpgradeSchema implements UpgradeSchemaInterface
{
    public function upgrade( SchemaSetupInterface $setup, ModuleContextInterface $context ) {
        $installer = $setup;

        $installer->startSetup();

        if(version_compare($context->getVersion(), '1.2.0', '<')) {
            $installer->getConnection()->addColumn(
                $installer->getTable( 'mageplaza_helloworld_post' ),
                'test',
                [
                    'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL,
                    'nullable' => true,
                    'length' => '12,4',
                    'comment' => 'test',
                    'after' => 'status'
                ]
            );
        }



        $installer->endSetup();
    }
}

此文件已正确更新

现在我也想用这样的新列更新我的表

<?php
namespace Mageplaza\HelloWorld\Setup;

use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;

class UpgradeSchema implements UpgradeSchemaInterface
{
    public function upgrade( SchemaSetupInterface $setup, ModuleContextInterface $context ) {
        $installer = $setup;

        $installer->startSetup();

        if(version_compare($context->getVersion(), '1.2.0', '<')) {
            $installer->getConnection()->addColumn(
                $installer->getTable( 'mageplaza_helloworld_post' ),
                'test123',
                [
                    'type123' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL,
                    'nullable' => true,
                    'length' => '12,4',
                    'comment' => 'test123',
                    'after' => 'status'
                ]
            );
        }



        $installer->endSetup();
    }
}

这不能正常工作

4

1 回答 1

0

似乎您在 addColumn() 定义中有错误。您应该使用“type”而不是“type123”。

于 2018-04-05T15:02:13.617 回答