Question

While running bin/Magento setup: upgrade command I am facing this error.

Schema creation/updates: Notice: Undefined index: core_store in /data/websites/website_url/public_html/vendor/magento/framework/Setup/Declaration/Schema/Db/SchemaBuilder.php on line 152

For Magento upgrade, I follow below link instructions but now facing this problem. https://digitalstartup.co.uk/t/how-to-upgrade-from-magento-2-2-8-to-2-3-1/528

Any help will be appreciated.

Was it helpful?

Solution

The problem is that the SchemaBuilder.php is attempting to look up a table that does not exist in the current database. You likely have an old foreign key table reference (from 1.9 perhaps) causing this failure.

You should run these 2 queries ( as example, tables and keys can be different ):

ALTER TABLE `wordpress_association` DROP FOREIGN KEY `FK_STORE_ID_WP_ASSOC`;
ALTER TABLE `wordpress_association` ADD CONSTRAINT `FK_STORE_ID_WP_ASSOC` FOREIGN KEY (`store_id`) REFERENCES `store` (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE;

EDIT

This issue could be cause also from other tables ( not just wordpress_association ). The root cause is a wrong REFERENCE in a FOREIGN KEY on one of your tables. Usually this is caused after a migration from Magento 1.x to Magento 2.x.

OTHER TIPS

To solve this issue I added an "if condition" to ignore the code if this [core_store] index will come.

// replace 
if($tables[$referenceTableName] != 'core_store' ){
    if (isset($tables[$referenceTableName]) && $referenceTableName !== $tableName) {
        $this->processReferenceKeys([$referenceTableName => 
        $tables[$referenceTableName]], $schema);
        unset($tables[$referenceTableName]);
    }
}

I solved this issue by doing following

  1. Exported the SQL dump for the database
  2. Searched for core_store from the error Undefined index: core_store
  3. Dropped all the foreign keys referencing that table
  4. Dropped that table altogether, as it was no longer needed.

That solved my problem.

But remember to keep database backup before doing that.

i have the same issue. I dont like to modify the core code. So i just opened this file:

vendor/magento/framework/Setup/Declaration/Schema/Db/SchemaBuilder.php

and add some debug messages, to see where the problem is. The script stops on FK dependencies on flat tables.

So my solution was to delete them. After this bin/magento setup:upgrade runs with out error!

I had the same error after adding a prefix (via phpmyadmin) to the table sequence_product and copying the table from another magento database into my database.

Problem: The prefixed table was still used instead of the copied one, so I had to find out which table is still using the prefixed table instead of the copied one.

I had to debug the file vendor/magento/framework/Setup/Declaration/Schema/Db/SchemaBuilder.php to add some debug output:

    private function processReferenceKeys(array $tables, Schema $schema)
    {
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/zend_debug.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);

        foreach ($tables as $table) {

$logger->info("Table: " . $table->getName());

            $tableName = $table->getName();
            if ($schema->getTableByName($tableName) instanceof Table) {
                continue;
            }
            $referencesData = $this->dbSchemaReader->readReferences($tableName, $table->getResource());
            $references = [];

            foreach ($referencesData as $referenceData) {
                //Prepare reference data
                $referenceData['table'] = $table;
                $referenceTableName = $referenceData['referenceTable'];
$logger->info("Ref-Table: " . $referenceTableName);
                $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]);
                }
            }

            $table->addConstraints($references);
            $schema->addTable($table);
        }
    }

Now run bin setup:upgrade again and look at the logfile /var/log/zend_debug.log.

Look at the last entries, you will see the table and the ref table. In my case it was the table email_catalog.

Now open the table in phpmyadmin, click on the tab structure then on relation view and select the correct table

enter image description here

enter image description here

What you should learn from this:

Never prefix a table to backup it! Instead create a new database and copy the tables you try to backup into it.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top