On this page
This is a data problem in the nopCommerce 5.00 upgrade that we found while reading the upgrade code for our StorePulse plugin. It only affects some older stores, it’s easy to prevent, and it’s tedious to clean up afterwards. This page explains the cause, how to check your store, and the fix before and after upgrading.
What you’d see after upgrading
- On a product page, choosing a colour or size shows the same picture twice in the gallery.
- In the admin area, an attribute value or combination lists the same picture twice.
- A picture you removed from a variant on 4.70–4.90 is back.
Product pictures themselves aren’t affected, only the pictures linked to attribute values (for example, a colour swatch’s picture) and to attribute combinations.
Why it happens
Two upgrades, four versions apart, handle the same data:
| Version | What happens |
|---|---|
| Up to 4.60 | Each attribute value and each attribute combination has one picture, stored in its own PictureId column. |
| 4.70 | Values and combinations can have several pictures, in two new tables. The upgrade copies each PictureId into them, then tries to clear PictureId, but that last step can be left unfinished. |
| 4.70–4.90 | nopCommerce only reads the new tables. Any PictureId left behind is invisible, so nobody notices it. |
| 5.00 | The upgrade copies every PictureId still set into the new tables again, without checking what’s there, then deletes the column. |
In the 4.70 upgrade code, the step that clears the old column is started but never waited for, so it can stop before it finishes. Where it stopped, the old links stay. The 5.00 upgrade then treats them as new and copies them a second time. Neither picture table prevents the same picture being linked twice.
The same leftover links explain the removed pictures coming back. Removing a picture on 4.90 deletes it from the new table, but the old column still pointed to it, so 5.00 adds it again.
Is your store affected?
- First installed on 4.70 or later: not affected. The old column was never filled.
- Upgraded through 4.70 from 4.60 or earlier: possibly. It depends on whether the 4.70 clean-up finished.
- No attribute pictures: not affected.
Check before upgrading
The free StorePulse plugin checks this as part of its 5.00 upgrade report: it counts the old links and how many of them would become duplicates. Or run this query on the 4.90 database:
SQL Server · count old picture links
-- SQL Server, on the 4.90 database. Read only.
SELECT
(SELECT COUNT(*) FROM ProductAttributeValue v
JOIN Picture p ON p.Id = v.PictureId) AS ValueLinks,
(SELECT COUNT(*) FROM ProductAttributeValue v
JOIN Picture p ON p.Id = v.PictureId
WHERE EXISTS (SELECT 1 FROM ProductAttributeValuePicture x
WHERE x.ProductAttributeValueId = v.Id AND x.PictureId = v.PictureId)) AS ValueDuplicates,
(SELECT COUNT(*) FROM ProductAttributeCombination c
JOIN Picture p ON p.Id = c.PictureId) AS CombinationLinks,
(SELECT COUNT(*) FROM ProductAttributeCombination c
JOIN Picture p ON p.Id = c.PictureId
WHERE EXISTS (SELECT 1 FROM ProductAttributeCombinationPicture x
WHERE x.ProductAttributeCombinationId = c.Id AND x.PictureId = c.PictureId)) AS CombinationDuplicates;Links is how many rows the 5.00 upgrade would copy. Duplicates is how many of those are already in the new table and would show twice. Links that aren’t duplicates are usually pictures that were removed after 4.70 and would come back.
Fix before upgrading: clear the old links
Since 4.70, nopCommerce doesn’t read the old column at all. What you see in the 4.90 admin area is what’s in the new tables. Clearing the old column changes nothing on 4.90, and leaves the 5.00 upgrade nothing to copy, so products look exactly the same after the upgrade.
SQL Server · clear old picture links on 4.90
-- SQL Server, on the 4.90 database. Back up first.
-- 4.90 never reads these columns, so the storefront doesn't change.
UPDATE ProductAttributeValue SET PictureId = NULL WHERE PictureId IS NOT NULL;
UPDATE ProductAttributeCombination SET PictureId = NULL WHERE PictureId IS NOT NULL;Run the check query again afterwards: both link counts should be 0. On MySQL or PostgreSQL the same statements work as written. Do this on the copy you test the upgrade with too.
Already upgraded? Remove the duplicates
Once you’re on 5.00 the old column is gone, so the duplicates have to be removed from the new tables. This keeps one row for each picture on each value or combination:
SQL Server · delete duplicate picture rows on 5.00
-- SQL Server, on the 5.00 database. Back up first.
-- Keeps the oldest row of each repeated picture and deletes the copies.
WITH d AS (
SELECT ROW_NUMBER() OVER (PARTITION BY ProductAttributeValueId, PictureId ORDER BY Id) AS n
FROM ProductAttributeValuePicture)
DELETE FROM d WHERE n > 1;
WITH d AS (
SELECT ROW_NUMBER() OVER (PARTITION BY ProductAttributeCombinationId, PictureId ORDER BY Id) AS n
FROM ProductAttributeCombinationPicture)
DELETE FROM d WHERE n > 1;Then click Clear cache in the admin header. Pictures that came back after being removed aren’t duplicates, so this doesn’t touch them. Compare the affected products with a 4.90 backup and remove those pictures in the admin area.
This is one of several things to check before a 5.00 upgrade. Our upgrade guide covers the process, and the nopCommerce 5.0 overview lists the other changes.
Frequently asked questions
Why do my product attribute pictures show twice after upgrading to nopCommerce 5.0?
The 5.00 upgrade copies the old one-picture-per-value links into the multiple-picture tables without checking whether the 4.70 upgrade already copied them. If the 4.70 upgrade didn’t clear those links, each picture ends up linked twice.
Does every store have this problem?
No. Only stores that were upgraded through 4.70 from 4.60 or earlier, and only if old picture links were left behind. Stores first installed on 4.70 or later have none. Run the check query, or the free StorePulse plugin, to know for sure.
Is it safe to clear PictureId on 4.90?
Yes. nopCommerce has ignored the column since 4.70; the storefront and admin area use only the multiple-picture tables. Clearing it changes nothing you can see, and gives the 5.00 upgrade nothing to copy. Back up the database first anyway.
A picture I removed from a variant is back after the upgrade. Why?
Removing a picture on 4.70–4.90 deletes it from the new table, but an old link left in PictureId still pointed to it. The 5.00 upgrade copied that link back. These can’t be told apart from real pictures automatically, so compare with a 4.90 backup and remove them in the admin area.
Can the duplicates be removed after upgrading?
Yes. Delete the repeated rows from the two picture tables, keeping one of each, then clear the cache. Pictures that came back after being removed need fixing by hand.
Next steps
Run StorePulse or the check query on your 4.90 store. If the counts are above zero, clear the old links before you upgrade. If you’ve already upgraded and the catalogue is large, we can clean it up for you, or check for it as part of our nopCommerce 5.0 upgrade service.