UpgradeSchema not working in Magento 2.2.5?
-
07-02-2021 - |
سؤال
I have make
setup:upgrade with changing module version
here is my code:
<?php namespace Tatva\ProductImport\Setup;
use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
class UpgradeSchema implements UpgradeSchemaInterface
{
/**
* {@inheritdoc}
*/
public function upgrade(
SchemaSetupInterface $setup,
ModuleContextInterface $context
) {
$installer = $setup;
$installer->startSetup();
if (version_compare($context->getVersion(), '1.0.1', '<')) {
$installer->getConnection()->addColumn(
$installer->getTable('product_import_details'),
'product_categories',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'nullable' => true
]
);
$installer->getConnection()->addColumn(
$installer->getTable('product_import_details'),
'product_url',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'nullable' => true
]
);
$installer->getConnection()->addColumn(
$installer->getTable('product_import_details'),
'product_download',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
'length'=>11,
'default'=>0,
'nullable' => true
]
)
;
}
$installer->endSetup();
}
}
المحلول
Make sure your module version should be 1.0.1 :
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Tatva_ProductImport" setup_version="1.0.1" schema_version="1.0.1">
</module>
</config>
Replace this below code in your upgradeschema file. I changed if condition format :
<?php
namespace Tatva\ProductImport\Setup;
use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
/**
* @codeCoverageIgnore
*/
class UpgradeSchema implements UpgradeSchemaInterface
{
/**
* {@inheritdoc}
*/
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$installer = $setup;
$installer->startSetup();
if (version_compare($context->getVersion(), '1.0.1') < 0) {
$installer->getConnection()->addColumn(
$installer->getTable('product_import_details'),
'product_categories',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'nullable' => true
]
);
$installer->getConnection()->addColumn(
$installer->getTable('product_import_details'),
'product_url',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'nullable' => true
]
);
$installer->getConnection()->addColumn(
$installer->getTable('product_import_details'),
'product_download',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
'length'=>11,
'default'=>0,
'nullable' => true
]
);
}
$installer->endSetup();
}
}
لا تنتمي إلى magento.stackexchange