0

I created and installed my database via the InstallSchema.php file. I now need to add a new column to one of my tables. In order to get the new column added to the table I deleted the module name entry from the setup_module table. I made my changes to to the InstallSchema.php file to add the additional column. Then I run the command "php bin/magento setup:upgrade" but the database is not being updated with the new column. Below is the code for the new column I am trying to add.

 ->addColumn(
                'api_status',
                \Magento\Framework\DB\Ddl\Table::TYPE_BOOLEAN,
                null,
                ['nullable' => false, 'default' => 0],
                'API Status'
            )
1
  • you have to add in UpgradeSchema.php file and change the version in module.xml
    – Vishnunath
    Nov 13, 2019 at 19:27

2 Answers 2

1

You should use UpgradeSchema for this, but if you don't care about the data in the existing table and just want a quick fix, delete the existing table, remove the row from setup_module, clear cache, and run setup:upgrade and your custom table should be created with your new column.

0

From Magento 2.3 it is recommend to use declarative schema. https://devdocs.magento.com/guides/v2.3/extension-dev-guide/declarative-schema/db-schema.html Try to replace old install scripts with declarative schema.

Please check this tutorials: https://www.mage2.tv/content/fundamentals/declarative-schema/ - Vinai Kopp explanation for declarative schema. https://inchoo.net/magento-2/declarative-schema/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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