10 votes
Accepted

How to assign a theme in Magento 2 using a setup script?

Create a new InstallData (or UpgradeData) script in either a new module or a fitting pre-existing module. Here is a simple example for a complete InstallData script. Simply replace the THEME_NAME ...
TiEul's user avatar
  • 1,297
9 votes

Magento 2: Create customer group programatically

Save method is deprecated in Magento 2 try this code: <?php /** * Copyright © 2018 MyCompany. All rights reserved. * See COPYING.txt for license details. */ namespace MyCompany\MyModule\Setup; ...
Mohamed El Mrabet's user avatar
7 votes

Magento 2: Create customer group programatically

Since the version 2.2.1 the use of the ->save() method from the Magento\Customer\Model\Group implementations has been deprecated. Instead, you should use: use Magento\Customer\Api\Data\...
Matias Nombarasco's user avatar
7 votes
Accepted

Error: DDL statements are not allowed in transactions while running setup:upgrade. Running Data Patch

After going through Declarative Schema docs again and referencing core magento code for Quote Module and Paypal Module I have figured that if you want to add a field into the existing table in Magento ...
PhantomS's user avatar
  • 503
6 votes
Accepted

Recurring.php and RecurringData.php

I've found this from online sources: The recurring scripts are executed after any module setup. If a module needs to do something everytime other modules are installed it can do it via the recurring ...
Adrian Z.'s user avatar
  • 707
5 votes
Accepted

Magento2: Setup Script not loaded

Install scripts only run when the module is initially installed. To have it run again, you need to remove that module's row from the setup_module table with a query like below: DELETE FROM ...
Aaron Allen's user avatar
  • 9,009
5 votes

How to assign a theme in Magento 2 using a setup script?

On Magento 2.1 and later (2.2 and 2.3 coming out) it is recommended to use service contract so I tried doing this without calling method in the model directly. Unfortunately at this point there is no ...
William Tran's user avatar
5 votes
Accepted

Magento 2 : Check Static Block with same identifier in InstallData Script

We can try: $cmsBlock = $this->blockInterfaceFactory->create(); $copyrightBlock = $cmsBlock->load('copy-right','identifier'); //And then check if (!$copyrightBlock->getId()) { ...... } ...
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

Magento 2 module install error "data: current version - none, required version 2.0.0"

Go and check "setup_module" table, the data_version is "null". This is happens because of something wrong while running "bin/magento setup:upgrade" So you have to fix the error then everything ok. ...
ManiMaran A's user avatar
  • 1,136
4 votes

How can I programmatically create a RESTful api role and consumer?

I was spent many hours searching and finally, I got the solution from Magento core. Magento itself provide code for create rest role programmatically and assign this role to the user. we can also ...
Niks's user avatar
  • 141
4 votes

Wrong entity ID exception in install script

People getting this error in Magento2: This seems to be an issue with dependency order during setup:upgrade with custom attributes. In Vendor/ModuleName/etc/module.xml, make sure to include a ...
sianguish's user avatar
4 votes

How to export/import configs in Magento?

Adding a late answer here to catch this post up to the current state of the times for the benefit of future Internet wanderers who find this. As Haijerome wrote, for a long time there was no ...
Scott Buchanan's user avatar
4 votes
Accepted

Magento2 setup not creating table

Note:: Delete module entry from tablesetup_module After testing the code i found out there were two error TYPE_Integer and TYPE_INTEGER tested code and workeing <?php /** * Copyright © 2016 ...
Qaisar Satti's user avatar
  • 32.5k
3 votes

Magento2: Setup Script not loaded

Same problem, I found the problem will appear when the module name have two or more capital letters, like Vendor\CapitalModule. I had set the folder name capitalization, namespace and class name is ...
Key Shang's user avatar
  • 3,415
3 votes

Start with clean database

Try the --cleanup-database in magento command line tool. Documentation
TFS's user avatar
  • 4,319
3 votes

How to export/import configs in Magento?

You can export (save) the database table core_config_data which holds all your store configurations. This feature is not available either in Magento 1.x versions or in Magento 2 (atleast not in ...
Haijerome's user avatar
  • 2,181
3 votes
Accepted

Problem in creating a table via custom module ( UpdateSchema.php )

Try below steps. Go to current Magento instances Database and remove the record from setup_module with module = 'Ved_Mymodule'. Remove the cache. Run the command php bin/magento setup:upgrade. Hope ...
Krishna ijjada's user avatar
3 votes

Magento 2 module install error "data: current version - none, required version 2.0.0"

This should work, you just need to execute following commands on terminal from magento root directory - rm -rf pub/static/* php bin/magento setup:static-content:deploy After that set 777 permission ...
InfoBeans's user avatar
  • 332
3 votes

How to assign a theme in Magento 2 using a setup script?

Above solutions work but have one shortcoming. They assume that magento has already registered the theme, before setup script execution. This is not always the case. If you revert entries in ...
zainengineer's user avatar
3 votes

Magento 2 - setup:install & setup:upgrade

when you are installing new extension at that time you need to run a command, php bin/magento setup:upgrade if you have already run command and you can change inside a module, you don't need to run ...
Rakesh Jesadiya's user avatar
3 votes

Custom Customer attribute that auto_increments

I am suggesting you to used Approach-3 with observer like this. In your extension config.xml file avilabel here. app\code\[CodePool]\[Company]\[Extension]\etc\config.xml define code like this: &...
Dhiren Vasoya's user avatar
3 votes
Accepted

Magento 2 new order attribute

The schema scripts is to create a database structure. For example, creating a table and add columns to existing table. The install data scripts is to manage the data within existing tables, adding ...
Khoa TruongDinh's user avatar
3 votes

Magento 2 :- Add select attribute to category

I used the following code to create attribute in InstallData.php. Vendor\Extension\Setup\InstallData.php <?php namespace Vendor\Extension\Setup; use Magento\Eav\Setup\EavSetup; use Magento\Eav\...
Dhiren Vasoya's user avatar
3 votes

Magento 2 :- Add select attribute to category

You need to add an node "options" to ui-component config <field name="roflcopter"> <argument name="data" xsi:type="array"> <item name="options" xsi:type="object">Magento\...
Eugen  Bogdanovich's user avatar
3 votes

Magento 2.1: Not add table into database

That is better if we take a look at the database after running setup upgrade command. If our custom table cannot be added to database. We need to check again. Remember to remove the setup module ...
Khoa TruongDinh's user avatar
3 votes
Accepted

Setup Script throws Error : Call to undefined method Mage_Core_Model_Resource_Setup::addAttribute()

The issue isn't with your setup script. You aren't using the proper setup resource in your config.xml. You need to use the Mage_Sales_Model_Resource_Setup model, not the default setup model. Example ...
Andrew Noble's user avatar
3 votes
Accepted

Insert multiple records to multiple custom tables through install script in magento2

You can use an InstallData script Try this: <?php namespace Vendor\Module\Setup; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use ...
fmsthird's user avatar
  • 4,592
3 votes
Accepted

Magento 2 - Customer Attribute not being saved

If You want to enable this attribute for admin customer form then you have to add below form area. 'adminhtml_customer' By changing ->addData(['used_in_forms' => [ '...
Amit Bera's user avatar
  • 77.5k
2 votes

Magento2 : How to database schema upgrade

To upgrade Installer Schema you have to write 'UpgradeSchema.php', example of UpgradeSchema.php: namespace <namespace>\<modulename>\Setup; use Magento\Framework\Setup\...
Sheshgiri Anvekar's user avatar

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