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&...
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 ...
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(...
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 ...
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 ...
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 ...
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\...
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');
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\...
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. ...
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 ...
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="...
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
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\...
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}
...
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\...
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 ...
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 $...
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"
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::...
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',
...
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 ...
3
votes
Magento 2 How to add foreign key in update schema
1 more important thing you need to do is make your column in foreign table is THE SAME as the column in your primary table or it will throw an error when you try to run "php bin/magento setup:upgrade",...
3
votes
Accepted
Magento 2 : Create product attribute with select box install script
Please do following suggestions in the install script.
Make 'user_defined' => true from 'user_defined' => false
In case the above solution didn't work, then remove the backend and source ...
3
votes
Accepted
Magento 2 : Creating widget using install script
This worked for me please try it.
$megaMenuWidget = [
'instance_type' => 'Magento\Cms\Block\Widget\Block',
'theme_id' => 2,
'title' => 'Test Megamenu Horizontal',
'store_ids' ...
3
votes
Recurring Upgrade Scripts in Magento 2.0, 2.1, or 2.2?
I think in devdocs there is another place where this is explained.
Magento executes your module’s recurring schema event class after every schema installation or upgrade stage. This class makes final ...
3
votes
Magento 2 - Create product attribute programmatically
Use below code in:
Vendor/Module/Setup/InstallData.php or Vendor/Module/Setup/UpgradeData.php
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->...
3
votes
Accepted
How to fix this "Running schema recurring.Unique constraint violation found"
"Running schema recurring.Unique constraint violation found" this occurs if there is duplicate entry in any table of project db and high probability to occur this problem is when you export db and ...
2
votes
my table is not installing in Magento 2
Some time there may an entry for you module in
app/etc/config.php
with value 0. And if you run the command
bin/magento setup:upgrade
then it will not upgrade your plugin. Change the vaue to 1 ...
2
votes
Accepted
Magento2 installSchema
If you want to update existing table/schema adding/updating row then,
Step 1: Create UpgradeSchema.php under Setup folder. Get Idea from following code.
namespace Vendor\ModuleName\Setup;
use ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
install-script × 146magento2 × 61
magento-1.9 × 30
database × 30
module × 15
attributes × 12
setup-script × 12
installation × 11
upgrade-script × 10
magento-1 × 9
magento-2.1 × 6
sql × 6
product-attribute × 5
model × 5
setup × 5
magento-1.8 × 4
magento-enterprise × 4
setup-upgrade × 4
table × 4
installer × 4
magento-1.7 × 3
php × 3
category × 3
magento2.2 × 3
error × 3