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: UPDATEurl_rewrite
SETrequest_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
- Login to admin back-end
- Click on Stores -> Configuration
- click on Catalog -> Catalog
- Open Search Engine Optimization
- Remove the .html suffix for both product and category
- hit Save
- I see the above error
What I did next
- I login to my phpMyAdmin
- Renamed the table by removing the
mag_
prefix forurl_rewrite
table - I flushed the cache in another browser and hit save in the current browser
- 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 thaturl_rewrite
table usage is hard-coded in theMagento\Catalog\Model\System\Config\Backend\Catalog\Url\Rewrite\Suffix
class. So when Search Engine Optimization configuration it triggers the classupdateSuffixForUrlRewrites()
method where the constant isn't wrapped with the getTableName() method call:There are 2 options on how to fix this issue:
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.backend_model
node for theCatalogUrlRewrite\etc\adminhtml\system.xml
fields with idcategory_url_suffix
andproduct_url_suffix
in your system.xml file:This option still requires you to fix it in your custom class.
My recommendation is to go with 1 or 2.