Note: The other answer from LitExtension relates to Magento versions <= M 2.1, more recent versions do not use url_path
attribute entries for URL rewrites. (Read more information in that answer for relevance - additional information related to this issue at the end of this answer as well).
This answer discusses the issue I solved eventually. My original question wanted assistance with comparing tables and specifically url_rewrite
table.
To summarize:
In my case the migration issue for error 404s were not the URL rewrites at all.
The issue I experienced is with catalog_product_entity and incorrect attribute_set_id's
assigned on migration.
My products and attribute sets were imported, but migration did not update the catalog_product_entity field attribute_set_id
correctly for most of my products. I had catalog_product_entity
rows (almost all rows) that had attribute_set_id x
, but in fact everything else were expecting attribute_set_id z
instead.
For instance:
The migration had both attribute_set_name AttributeSetName
and attribute_set_name Migration_AttributeSetName
as well (All attribute sets had a AttributeSetName and Migration_AttributeSetName
version.
The migration then attached products to Migration_AttributeSetName
to catalog_product_entity
but should have been using AttributeSetName
.
SOLUTION
(Summary version)
Please note that this information should be used as a starting point, and the queries mentioned below should be investigated with your individual case to see if your data has some additional filters required.
Three steps are needed:
- Create a filter of matching attribute sets with a
sourceid
and targetid
attribute_set_id
INNER JOIN the catalog_product_entity
table to use that filter to see which products will be updated and store it into a temporary table or view.
- Create a loop (most likely stored procedure) that can update the
catalog_product_entity
table using the results of the temporary table/view.
UPDATE catalog_product_entity SET attribute_set_id = targetid WHERE attribute_set_id = sourceid
- (Optional - but recommended)
Use Elgentos Regenerate URL Module which will help you regenerate all your categories/product/cms-page urls because Magento 2 does not have this capability built-in anymore (it only refreshes on individual product save).
(Explanation)
- Use this filter as reference:
This query filters out those products that have an attribute set WHERE NOT LIKE %Migration%
:
(SELECT DISTINCT(attset.attribute_set_id) AS LookupAttributeSetId, attset.attribute_set_name AS LookupAttributeSetName,
CONCAT("Migration_", attset.attribute_set_name) AS TargetAttributeSetName
FROM catalog_product_entity AS prod
INNER JOIN eav_attribute_set AS attset
ON prod.attribute_set_id = attset.attribute_set_id
WHERE attset.attribute_set_name
NOT LIKE "%Migration%") ;
- Then expanding on this:
INNER JOIN eav_attribute_set AS targetset
and store the information into a View/Temporary Table
:
CREATE TEMPORARY TABLE _resultset_updatethese_attribute_setids_in_catalog_product_entity_ AS (
SELECT FilteredResults.*, targetset.attribute_set_id AS TargetAttributeSetId FROM
(SELECT DISTINCT(attset.attribute_set_id) AS LookupAttributeSetId, attset.attribute_set_name AS LookupAttributeSetName,
CONCAT("Migration_", attset.attribute_set_name) AS TargetAttributeSetName
FROM catalog_product_entity AS prod
INNER JOIN eav_attribute_set AS attset
ON prod.attribute_set_id = attset.attribute_set_id
WHERE attset.attribute_set_name
NOT LIKE "%Migration%")
AS FilteredResults
INNER JOIN eav_attribute_set AS targetset
ON targetset.attribute_set_name = FilteredResults.TargetAttributeSetName);
- Then update all those
attribute_set_id
entries that are currently assigned to the catalog_product_entity
table that were stored in the temporary table/view (I only managed to do this using a Stored Procedure and **looping through each row in order to get the current attribute_set_id
and the 'target' attribute_set_id
from that result set.
UPDATE catalog_product_entity
SET attribute_set_id = newid
WHERE attribute_set_id = targetid (_IN THAT LOOKUP result (each row needs sourceid and targetid)_).
- (Optional - but recommended)
Use Elgentos Regenerate URL Module which will help you regenerate all your categories/product/cms-page urls because Magento 2 does not have this capability built-in anymore (it only refreshes on individual product save).
This should update most of your catalog which should fix error 404 if your issue is similar.
NOTE: I have noticed some of my products have not been updated using this method, but ~90% of my products work now!
(Additional Information)
Regarding <= M2.1 and url_path
Just in case the other answer does not have this information anymore:
Elgentos Regenerate Catalog URLs module explains on url_path
on its readme:
However, the use of url_path has been deprecated since early Magento 2.1 versions (see here). If you are running on a recent Magento 2 version, you can safely delete those values by running DELETE FROM catalog_product_entity_varchar WHERE attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'url_path' AND entity_type_id = 4)