Magento 2 – Unable to Save Catalog Config

databasemagento2

Got the below error while updating the catalog configuration.

Something went wrong while saving this configuration: SQLSTATE[42S02]:
Base table or view not found: 1146 Table 'dbname.url_rewrite' doesn't
exist, query was: UPDATE url_rewrite SET request_path = ? WHERE
(url_rewrite_id = 62)

One thing I noticed is the table shown in the error doesn't have the table prefix. This is a migrated website from Magento 1.9.1.0 and we use table prefix.

Am I doing something wrong? or is this a core issue?

Update: I guess it is a bug. I just removed the prefix for url_rewrite table alone and the save works great. But after save it throws a similar error for SELECT.

Steps I followed

  1. Login to admin back-end
  2. Click on Stores -> Configuration
  3. click on Catalog -> Catalog
  4. Open Search Engine Optimization
  5. Remove the .html suffix for both product and category
  6. hit Save
  7. I see the above error

What I did next

  1. I login to my phpMyAdmin
  2. Renamed the table by removing the mag_ prefix for url_rewrite table
  3. I flushed the cache in another browser and hit save in the current browser
  4. Now the save works but when the page refreshed it shows the table mag_url_rewite doesn't exist.

It looks clearly a bug for me… Sorry if I might be wrong…

Best Answer

Thank you for exception.log data. You are right that url_rewrite table usage is hard-coded in the Magento\Catalog\Model\System\Config\Backend\Catalog\Url\Rewrite\Suffix class. So when Search Engine Optimization configuration it triggers the class updateSuffixForUrlRewrites() method where the constant isn't wrapped with the getTableName() method call:

        $this->connection->update(
            DbStorage::TABLE_NAME,
            $bind,
            $this->connection->quoteIdentifier(UrlRewrite::URL_REWRITE_ID) . ' = ' . $urlRewrite->getUrlRewriteId()
        );

There are 2 options on how to fix this issue:

  1. Plugin for the Magento\Catalog\Model\System\Config\Backend\Catalog\Url\Rewrite\Suffix:: updateSuffixForUrlRewrites() method. For this we have to inject all dependencies which Suffix has in it's contructor.
  2. Update backend_model node for the CatalogUrlRewrite\etc\adminhtml\system.xml fields with id category_url_suffix and product_url_suffix in your system.xml file:

enter image description here

This option still requires you to fix it in your custom class.

  1. Pull request into Magento 2 repository with the fix. You might wait a while until it will be available in stable release.

My recommendation is to go with 1 or 2.

Related Topic