We have a 404 issue on all product pages. Category pages showing fine as they should. Having imported circa 4000 products directly into our Magento2 store database and uploading images directly to the media folder, I realise we have omitted the correct steps for Magento2 in that we have not used the inbuilt import function. Thus the URL rewrite function has not ran.

When we create a new product manually from the Magento admin, the same issue occurs though. We have a 404 error in the frontend for the URL that is created. We can see the URL's are creating in the catalog_url_rewrite_product_category and url_rewrite tables.

We have re-ran below list of queries on command line to try to rectify:

php bin/magento setup:di:compile

php bin/magento setup:static-content:deploy en_US en_GB

php bin/magento setup:upgrade

php bin/magento cache:clean

php bin/magento cache:flush

And reset permissions as per below guide:

Magento 2 folder/file permissions

We are running the latest version of Magento 2.1.6 having upgraded recently to see if this solves the issue.

My feeling is that there is something corrupt in the database, but unsure how to debug further. And/or it's a permission issue as our cron is not running currently too which is another issue we are looking to fix today.

Any help and guidance would be greatly appreciated. Thanks.

  • Should also mention we have tried a number of other methods not listed above including upgrading db from command line and adding all products to store manually from update attributes function of product grid. Still 404 error exists.
    – MagentoMac
    Commented May 11, 2017 at 9:05
  • You should just import data from "report_event_types". Commented Jan 29, 2020 at 10:44

2 Answers 2


I've worked out how to fix this for our particular situation. It was a corrupt database table issue. So error from system.log file relevant is below:

main.CRITICAL: PDOException: SQLSTATE[23000]: Integrity constraint violation: 
1452 Cannot add or update a child row: a foreign key constraint fails 
REFERENCES `report_event_types` (`event_type_id`) ON DELE) 
in /var/www/vhosts/domain.com/httpdocs/vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:228

Restoring the report_event table to a previous version before the migration of product content from Squarespace from a month or so back did the trick. This product the product URL back to life and allowed us to add products to the cart again. Hope this helps somebody else one day for similar issue.


Well, most important thing to notice is your products must have positive stock, they must be enabled and there visibility should becatalog search. Assuming you have this run

php bin/magento indexer: reindex 

and notice the time it takes. This should pretty much fix the issue. I insist on checking all of above parameters because you say the urls exist in url_rewrite table. What happens when you search for the product in search bar? Let's say this doesn't fix your issue. You can export the products using magento backend. Then change the url key column for each row... May be you can append product sku... Then reimport. If import fails you will know the problem. If it doesn't then your problem will be solved. I'm curious as to how you directly imported data into database because there are so many foreign key constraints..

  • You aren't understanding the issues and the suggestions wouldn't result in a 404. Even if a product has 0 for quantity and doesn't have catalog search, the URL will still generate and show in frontend.
    – MagentoMac
    Commented May 10, 2017 at 21:18
  • The command php bin/magento indexer: reindex doesn't effect URL but yes has already been ran multiple times. The products appear in search fine and in the categories fine. The "ugly" URL's that should redirect to the proper URL do not load either.
    – MagentoMac
    Commented May 10, 2017 at 21:20
  • And yes we can export the products fine and then re-import them fine but any product still generates a 404 error. I think the issue is database related because we imported directly into the database. We did so because of an import from Squarespace to Magento to carry the sizes and colours through to work with Magento structure. It's a long story in honesty! And trying to just cover the key details in this post.
    – MagentoMac
    Commented May 10, 2017 at 21:21
  • I think the issue here is the database being corrupt, because of the way we imported from Squarespace. But no idea how to debug and fix..... aware of how to compare 2 databases with Magento1 but unsure if the same concept can be applied to Magento2..... thanks for your help though. Really appreciate you trying and suggesting things. Thanks.
    – MagentoMac
    Commented May 10, 2017 at 21:24
  • Can you share the screen shot of the error. Couple of examples will be greatly helpful Commented May 11, 2017 at 3:36

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.