I was following the below tutorial https://www.integer-net.com/make-magento-2-small-again/ and removing modules etc from magento and trying to get setup:di:compile
to work in my dev environment. Everything seemed fine (other than compilation) for a bit however after fiddling (removing modules and adding them back trying to get setup:di:compile
to work) for a while I started getting below issue:
Running bin/magento setup:upgrade
below error shows during Schema creation/updates:
Schema creation/updates:
Notice: Undefined index: inventory_stock in /var/www/magetest/public_html/vendor/magento/framework/Setup/Declaration/Schema/Db/SchemaBuilder.php on line 152
I restored all the modules (did not work) and I tried reindexing however that had no effect. Then restored an old database etc however the problem persists continuously.
The problem seems to be due to a missing table however that table seems to exist in my database. I'm running Magneto 2.3.3 however the backup database that i've had to go back from are a 2.2.7 instance that i'm now trying to upgrade.
I've also tried stating a fresh new vanilla instance and update the old database however the issue persisted again when running setup:upgrade.
I have also tried updating from 2.2.7 to 2.3.0 instead in hope that would fix however same error agian. I am out of ideas and so any simple suggestions to fix this may help me save some time!
UPDATE
OK really unhappy with what I had to go to fudge this into operation but will explain an may help someone figure out a better fix.
So I conditionally removed out the section which was giving an error for the case where the reference table was "inventory_stock":
Magento\Framework\Setup\Declaration\Schema\Db\SchemaBuilder;
foreach ($referencesData as $referenceData) {
//Prepare reference data
if($referenceData['referenceTable'] != "inventory_stock") {
$referenceData['table'] = $table;
$referenceTableName = $referenceData['referenceTable'];
$referenceData['column'] = $table->getColumnByName($referenceData['column']);
$referenceData['referenceTable'] = $this->tables[$referenceTableName];
$referenceData['referenceColumn'] = $referenceData['referenceTable']->getColumnByName(
$referenceData['referenceColumn']
);
$references[$referenceData['name']] = $this->elementFactory->create('foreign', $referenceData);
//We need to instantiate tables in order of references tree
if (isset($tables[$referenceTableName]) && $referenceTableName !== $tableName) {
$this->processReferenceKeys([$referenceTableName => $tables[$referenceTableName]], $schema);
unset($tables[$referenceTableName]);
}
}
}
For some reason the build function was not adding the table "inventory_stock" to the tables array and when trying to process reference keys for the table "inventory_stock_sales_channel" the referenceTable "inventory_stock" did not exist so threw an error (not sure if the table shuoldn't of existed in referenceData and so threw an error because of reverse of above).
Removing the above was just a test but allowed me to get to another error about cannot create the "inventory_stock" table as it already existed.
So I decided to remove it from DB and let Magento recreate it properly.
I then removed the mod above and tried again and all worked. I had to recreate stock codes as was getting errors about stock codes not existing.
Feel this is a long way around and recreating the table correctly may have been the easiest approach however nothing seemed to work for me until Magento created it. Or possibly just deleting the table but sure I tried that.
yireo replace git
. Take a look at composer meta packages. The bundled one works for me. That's a happy medium. Also worth highlighting that newer version of MSI (inventory) is a lot faster. This is the version that will be released with 2.3.4.