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'
 )
asked Nov 13, 2019 at 17:35
1
  • you have to add in UpgradeSchema.php file and change the version in module.xml Commented 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.

answered Nov 13, 2019 at 20:10
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/

answered Nov 13, 2019 at 19:45

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.