0

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?

  • 1
    I think I found out why, I must delete my modules from setup_module and then run setup:upgrade? I thought by giving a higher module version in module.xml is enough. – Magento Learner Apr 7 '18 at 8:23
  • check my answer, it will help you more. – Emipro Technologies Pvt. Ltd. Apr 7 '18 at 11:21
2

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

  • so I i just give a higher version in module.xml, this won't help? must record from setup_module be deleted everytime I want to run setup:upgrade? – Magento Learner Apr 7 '18 at 10:48
  • 1
    If you want to to use versioning, you need to create new file [UpgradeSchema.php], and add your code here, please follow this it has more information . magento.stackexchange.com/a/86089/31830 – WISAM HAKIM Apr 8 '18 at 14:41
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.