문제

I have created my custom module to add more attributes for customers.

The InstallData.php worked perfectly for the first time and added all the attributes I wanted.

However, I need to add more attributes. I updated my InstallData.php and run php bin/magento setup:upgrade, but the new attributes are not added.

What did I miss in this problem?

도움이 되었습니까?

해결책

Delete your module from setup_module table and run php bin/magento setup:upgrade

다른 팁

Delete your module from setup_module table in a database and also require to delete your database table which is useful in InstallData.php.

If you don't want to delete your database table then you can also use UpgradeSchema.php file to add more attributes in the database.

Create Vendor/Module/Setup/UpgradeSchema.php

<?php

namespace Vendor\Module\Setup;

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

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

        $installer->startSetup();
        $installer->getConnection()->addColumn(
            $installer->getTable('table_name'),
            'table_field_name',
            [
                'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                'length' => '2M',
                'nullable' => false,
                'default' => null,
                'comment' => 'Custom Attribute',
            ]
        );
        $installer->endSetup();
    }
}

I hope this will help you.

The right way of doing it is using UpgradeData. This way you don't touch on the already existing data installed by InstallData. Only thing to note is change the setup_version in module.xml.

There is an answer for this question already here

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top