I tried a test upgrade on a staging site for an old project...
I had Drupal 5.ancient and image 5-1.
I got this warning when upgrading:
user warning: Duplicate entry '31-thumbnail' for key 1 query: INSERT INTO image SELECT DISTINCT u.nid, f.fid, f.filename FROM upload u INNER JOIN files f ON u.fid = f.fid INNER JOIN node n ON u.nid = n.nid WHERE n.type = 'image' AND f.filename IN ('_original', 'thumbnail', 'preview', 'feature') in D:\xampp\htdocs\drupal-work-newport-upgrade\sites\all\modules\image\image.install on line 271.
My upgraded site seems fine, but some nodes have no images -- node 31 and nodes with higher nids than that.
So basically the SQL error caused the transfer of data from {files} to {images} in image_update_5200 to stop.
Here's the relevant bit of my OLD file table from the 5-1 database:
60 31 _original files/images/Playground.jpg image/jpeg 133339
61 31 thumbnail files/images/Playground.thumbnail.jpg image/jpeg 3632
62 31 feature files/images/Playground.feature.jpg image/jpeg 18162
63 31 thumbnail files/images/Playground.thumbnail.jpg image/jpeg 3632
64 31 feature files/images/Playground.feature.jpg image/jpeg 18162
Trying to run just that one query on this in phpmyadmin produces the same error, because there are 2 entries with nid 31 and 'thumbnail'. Obviously this is bad data, and I have no idea how it came about.
But have we had other reports of missing images after upgrade? This might be one of the causes.
On the plus side, upgrade from 5-1 to 6-dev worked perfectly apart from this. I have images, I can make new images, I have attached images and I have galleries!
The galleries taxo lost images though -- have we not committed that fix yet?
Comments
Comment #1
sunIRC?
Comment #2
joachim commentedHmm okay I see a few duplicates of this... oops :D
Looking at another old site, I get the same error for 100-thumbnail, but my data seems ok:
Baffled....
Comment #3
sunNo IRC available?
So the issue seems to be that
SELECT DISTINCT u.nid, f.fid, f.filenamedoes not seem to be taken into account.Potentially, because we need u.nid + f.filename to be unique. And f.fid is in between.
...is queried as:
But we want:
Two options:
a) Remove {img_assist}.image_size from primary key.
b) Refactor that database update to fetch all data first, make it unique, and only afterwards insert into {img_assist}.
Comment #4
joachim commentedSorry, didn't see your comment last night and thought I was only replying to myself...
I don't know enough about primary keys and what we need them for, so I'm not sure what's best.
Comment #5
raintonr commentedHow is this related to #207557: update 5-1 to 5-2 gives user warning: Duplicate entry '611-thumbnail' for key 1 query in image_update_5200?
Comment #6
joachim commentedLooks like the same error message. We should consolidate issues.
Comment #7
Leeteq commentedSubscribing.
Comment #8
joachim commentedRelated to #424386: images saved to files table with bad data in filename column?
In haste, only have internets in passing. If someone could do the rounds of the possibly related issues and mark as duplicates if they are, that would be great.
Comment #9
joachim commentedIt's been suggest to me that we use
REPLACE INTO
rather than
INSERT INTO
which guarantees that if a row already exists it's replaced instead.
Would that fix it?
http://dev.mysql.com/doc/refman/5.0/en/replace.html
Comment #10
joachim commentedMarking as duplicate of #207557: update 5-1 to 5-2 gives user warning: Duplicate entry '611-thumbnail' for key 1 query in image_update_5200, which has a fix.