40 votes
Accepted

When we look at an eavSetup what values are available for type and input?

You can find type and input value from the database eav_attribute table. Type datetime decimal int static text varchar Input boolean date gallery hidden image media_image multiline multiselect ...
Rakesh Jesadiya's user avatar
20 votes
Accepted

my table is not installing in Magento 2

In Magento 2 version information is stored on setup_module table. So you can remove your module and re run the commands it will work.
Manoj Kumar's user avatar
  • 1,348
16 votes

Magento 2 How to add foreign key in update schema

Try this: ->addForeignKey( $installer->getFkName('<ChildTable>', 'entity_id', '<ParentTable>', 'entity_id'), 'entity_id', $installer->getTable('<ParentTable&...
Ronak Chauhan's user avatar
12 votes
Accepted

Magento2 InstallSchema Error 1215

data type for the child column must match the parent column exactly. check data type in table store store_id (type is smallint) and your store_id is INTEGER.
Anand Ontigeri's user avatar
11 votes
Accepted

When schema_version & data version will be different?

data_version is the version of data added via the data scripts. Those scripts are developed under the module folder under the Setup/InstallData.php and Setup/UpgradeData.php. schema_version is the ...
Raphael at Digital Pianism's user avatar
8 votes

How to fix this "Running schema recurring.Unique constraint violation found"

To see the actual error, you need to run the data upgrade command on it's own: php bin/magento setup:db-data:upgrade And suddenly, after many hours of searching and debugging one gets to see the ...
Alex's user avatar
  • 185
6 votes
Accepted

Make column unique in install schema script

You can use addIndex method having type \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE, like: $table = $installer->getConnection()->newTable( $installer->getTable(...
Siarhey Uchukhlebau's user avatar
6 votes
Accepted

Magento 2: Run a uninstall script when module is uninstalled via command line?

Magento Setup Uninstall script The below page in the Magento DevDocs explains the process of module uninstallation. It explains the steps that are taken and one of those steps is running Uninstall ...
7ochem's user avatar
  • 7,532
6 votes

Recurring Upgrade Scripts in Magento 2.0, 2.1, or 2.2?

Alan, first of all, I want to say thank you for your blog. I learned a lot of Magento thing using it. Thanks a lot. About the Recurring.php: These scripts are fired every time u run setup:upgrade ...
Stepan Furman's user avatar
6 votes
Accepted

Force-run module install script in Magento 2

If you are trying to run installation scripts for a "local" module (not installed with composer) and the module is already installed, you should: Remove module installation registry from database, in ...
Dani Garval's user avatar
6 votes
Accepted

Magento 2 how to add data to custom column in sales_order table

Setup/InstallSchema.php <?php namespace [Vendor]\[Module]\Setup; use Magento\Framework\Setup\InstallSchemaInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\...
Sweety Masmiya's user avatar
5 votes
Accepted

How to create MySQL Triggers through setup script

We can use \Magento\Framework\DB\Ddl\TriggerFactory to create mysql triggers through setup script: (not test yet) class UpgradeSchema implements UpgradeSchemaInterface { /** * @var \Magento\...
Khoa TruongDinh's user avatar
5 votes
Accepted

Custom customer attribute are throwing error at Customer edit Page - Magento2

We should try with getCustomAttribute() $block->getCustomer()->getCustomAttribute('codes_for_apply');
Khoa TruongDinh's user avatar
5 votes
Accepted

Magento2 What's the point of having both InstallSchema and UpgradeSchema

I got this question in a training I was giving, and we tried out if we need InstallSchema / InstallData at all. It turned out we don't need it, as the Upgrade classes are executed on installation too. ...
Andreas von Studnitz's user avatar
4 votes
Accepted

Magento 2 command line install (too many arguments)

I think you have forgot about the -- in front of the command. (So it seems in your screenshot).
Akif's user avatar
  • 1,531
4 votes

How to add new column to existing table in Magento programmatically?

I realize this is a relatively 'old' question, but as it's still pretty find-able by Google, I decided to add this bit of information. Regarding your question, if you want to change the sales/order ...
Wesley Vestjens's user avatar
4 votes
Accepted

Add category attribute to custom attribute group

Thanks to @SohelRana I found out that you now have to write a bunch of additional XML to make anything appear in the category form. Since the answer linked above does not explain how to add a new ...
Fabian Schmengler's user avatar
4 votes

Magento 2 How to add foreign key in update schema

Sample for foreign key, <table comment="projectfinder_attributevalue Table" engine="innodb" name="projectfinder_attributevalue" resource="default"> <column comment="Entity Id" identity="...
Kazim Noorani's user avatar
4 votes
Accepted

Magento 2 - InstallData.php does not run again after first time

Delete your module from setup_module table and run php bin/magento setup:upgrade
Vinu Sebastian's user avatar
4 votes
Accepted

how to add collation( utf8_general_ci) using install schema in magento2?

Add this below script in InstallSchema.php file : <?php namespace VendorName\ModuleName\Setup; use Magento\Framework\Setup\InstallSchemaInterface; use Magento\Framework\Setup\...
Rohan Hapani's user avatar
  • 17.4k
4 votes
Accepted

Magento 2 : create view table via setup script

Magento itself in the rather newish inventory project creates the inventory_stock_* tables itself via plain SQL: $sql = "CREATE SQL SECURITY INVOKER VIEW {$viewToLegacyIndex} ...
Simon's user avatar
  • 5,735
3 votes
Accepted

How do I specify unique constraint for multiple columns in InstallSchema.php?

Problem solved: in the script, I directly executed the request: $myRequest = "ALTER TABLE..."; $installer->getConnection()->query($myRequest ); EDIT: finally found how to do it with the ...
enrico69's user avatar
  • 515
3 votes

Install script will not execute

You can delete the record "pinterestimage_setup" from the database table core_resource instead of changing "pinterestimage_setup" to "mymod_pinterestimage_setup"
user51486's user avatar
3 votes
Accepted

Customized field got disappeared in catalog_product_flat_1 table

The flat tables for products and categories are dynamic. They are generated on the fly when you reindex based on several criterias. For the products it's based on whether or not the product attribute ...
Raphael at Digital Pianism's user avatar
3 votes

Magento 2 datatypes. Need TIME (of day)

I solved this by using DATETIME initially $table = $installer->getConnection() ->newTable($installer->getTable('MYTABLE')) ->addColumn( 'MYCOLUMN', ...
Kampaviineri's user avatar
3 votes
Accepted

Magento: how to log messages in custom module install script?

Yes I faced the problem before, the only way I managed to get it working was by forcing the log by setting the 4th parameter of Mage::log to true so in your case I suggest you use the following code ...
Raphael at Digital Pianism's user avatar
3 votes
Accepted

How can I create an attribute as "not configurable" from an install script?

You should actually use Mage_Catalog_Model_Resource_Setup::addAttribute() instead of Mage_Eav_Model_Entity_Setup::addAttribute() As you have found out in the code, Mage_Eav_Model_Entity_Setup::...
Sébastien's user avatar
3 votes

When implementing an SQL upgrade script, do I need an install script for stores that have never had a previous version of the module?

As long as you follow the right naming convention, example: install-0.1.0.php upgrade-0.1.0-0.2.0.php upgrade-0.2.0-1.0.0.php Magento will first check if the module is installed. If it's not ...
Raphael at Digital Pianism's user avatar
3 votes
Accepted

How can i can run install script from controller without error

The constructor method for Mage_Core_Model_Resource_Setup defines a single parameter which is required to create an object instance: public function __construct($resourceName) {...} The $...
duttyman's user avatar
3 votes
Accepted

I need to add to tables to database using InstallSchema.php How can i do that?

You can add as many table as you want in your installSchema file. Refer below code <?php namespace Test2\Helloworld\Setup; use \Magento\Framework\Setup\InstallSchemaInterface; use \Magento\...
Priyank's user avatar
  • 7,682

Only top scored, non community-wiki answers of a minimum length are eligible