3

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.

3

6 Answers 6

4

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.

4
  • 1
    Why wordpress_association ?
    – Black
    Commented Sep 21, 2020 at 9:11
  • Hi, actually this is caused on every wrong foreign key. I've found the same error also on other tables migrated from 1.9 to 2.3. Commented Sep 22, 2020 at 10:43
  • But I wonder why you choosed wordpress_association. The OP did not mention wordpress nowhere?
    – Black
    Commented Sep 22, 2020 at 10:48
  • Because i had the same issue and was caused on this particular table. Later i had this also on other tables, the root cause is the foreign keys, independent of the specific table. Commented Sep 23, 2020 at 9:36
6

The accepted answer is not the right one, it's not sure that those wordpress tables are causing the error. Find the incriminated table first

SELECT
    TABLE_NAME,
    CONSTRAINT_NAME 
FROM
    INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE
    REFERENCED_TABLE_NAME = 'core_store';

then you can drop the FK

ALTER TABLE <table_name> DROP FOREIGN KEY <constraint_name>;
2

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.

1

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]);
    }
}
2
  • or you can copy paste these Empty tables in your Database (core_store, core_website) from Magento 1.9 Commented Jul 1, 2019 at 8:34
  • This is a temporary solution. The correct answer of your question is shared by @MarcoValenziano. You need to figure out the tables using wrong foreign key constrains to fix this problem.
    – Sumit
    Commented Mar 11, 2020 at 12:51
0

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.

0

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.