6.x upgrade error: Unknown column 'f.nid' in 'field list' query

yngens - May 13, 2008 - 00:57
Project:Image
Version:6.x-1.0-alpha4
Component:image.module
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed
Description

Upgrading to 6.x-1.0-alpha1 gives an error:

# user warning: Unknown column 'f.nid' in 'field list' query: INSERT INTO image SELECT DISTINCT f.nid, f.fid, f.filename FROM files f INNER JOIN node n ON f.nid = n.nid WHERE n.type='image' AND f.filename IN ('_original', 'thumbnail', 'preview') in /home/mysite/public_html/sites/all/modules/image/image.install on line 252.
# user warning: Table 'mariposa_mariposa.file_revisions' doesn't exist query: DELETE FROM file_revisions WHERE EXISTS (SELECT * FROM image WHERE image.fid = file_revisions.fid) in /home/mysite/public_html/sites/all/modules/image/image.install on line 255.

#1

jvandervort - May 13, 2008 - 18:14

I had the same problem. I upgraded from drupal 5.x to drupal 6.x and it removes the f.nid column from the files table before the image module update query runs. I had to restore my old version of the files table to file_old, and modify the insert query above to

INSERT INTO image SELECT DISTINCT f.nid, f.fid, f.filename FROM files_old f INNER JOIN node n ON f.nid = n.nid WHERE n.type='image' AND f.filename IN ('_original', 'thumbnail', 'preview')

A little bumpy, but it worked.

#2

artem_sokolov - July 27, 2008 - 06:26
Version:6.x-1.0-alpha1» 6.x-1.0-alpha2

Confirming this in alpha2.

I experienced this issue while upgrading from Drupal 5.4 to Drupal 6.3 and jvandervort's workaround worked.

In case somebody needs, my steps to follow it were:
1) launch in command prompt: mysqldump -u USERNAME -pPASSWORD OLD_DATABASE files > files.sql
2) in file files.sql replace in some editor string `files` with string `files_old` (with quotes)
3) launch in command prompt: mysql -u USERNAME -pPASSWORD NEW_DATABASE < files.sql

The table file_revisions seems to have been deleted before image module update, so no workarounds are needed.

#3

sandalle - August 10, 2008 - 04:51
Priority:normal» critical

I *love* you two, you just saved my wedding website! ;) Also note that after doing artem_sokolov's step (#2) and then jvandervort's step (#1), you will want to re-run the update.php script. My thumbnails did not come back after running solely #2 and #1, but after I ran update.php, the world was good. :)

This happened after upgrading Drupal 5.9 with image-5.x-1.9 to Drupal 6.3 with image-6.x-1.0-alpha2.

#4

stdbrouw - August 10, 2008 - 20:42

I was unfortunate enough to have no backup available, but I solved my misery this way:
INSERT INTO image (nid, fid, image_size) SELECT u.nid, f.fid, f.filename FROM files f LEFT JOIN upload u ON f.fid=u.fid
If you have trouble with the primary key, just temporarily remove it. Note that you'd need to refine this query if you've also uploaded files and not just images, because this query takes its information from the upload table.

#5

jandd - August 16, 2008 - 19:50

A full corrected statement with drupal table name placholders taking care of the filenames and image node type too is:

insert into {image} SELECT distinct u.nid, u.fid, f.filename from {files} f, {upload} u, {node} n where f.fid=u.fid and u.nid=n.nid and n.type='image' and f.filename in ('_original', 'thumbnail', 'preview')

#6

jandd - August 16, 2008 - 19:59

I just had a look in CVS head's image.install. The update containing the problematic SQL code is contained in function image_update_5200(). This is a function that would work in drupal 5 and has been introduced for the not yet finalized 5.x-2.x release. Updating from 5.x-2.x to 6.x-1.x should work. Updating from 5.x-1.x to 6.x-1.x does not work. I don't know if it is possible to get both update paths working.

#7

jandd - August 16, 2008 - 21:59
Assigned to:Anonymous» jandd
Status:active» needs review

I created the attached patch to fix this issue. I upgraded successfully from a drupal 5.10 installation using image 5.x-1.9 to drupal 6.4 using image from CVS head. The patch applies cleanly against image.install in CVS.

AttachmentSize
image_257743_image.install.patch 1.71 KB

#8

drewish - August 17, 2008 - 08:02

I'm not sure about the whole VERSION constant. Where does that come from?

#9

jandd - August 17, 2008 - 12:18

The VERSION constant is defined in modules/system/system.module see http://api.drupal.org/api/constant/VERSION/6 and http://api.drupal.org/api/constant/VERSION/5. The constant is available in D4.7 till D7.0-dev and seems a reliable indicator for the running Drupal version.

#10

sun - August 17, 2008 - 16:44
Status:needs review» needs work

Please remove the conditional VERSION code. Updates in a 6.x module are for 6.x, and updates in a 5.x module are for 5.x.

I'm a bit unsure about the WHERE EXISTS statement... is that known to work in all and each and every edge-case?

#11

jandd - August 17, 2008 - 17:26

The patch tries to address the case that users of the 5.x-1.x series face. The current 6.x-1.x version expects that 5.x-2.x is installed and has the mentioned problems when updating from 5.x-1.x to 6.x-1.x. The VERSION condition applies if a user updates from 5.x-1.x. If he updates from 5.x-1.x to 5.x-2.x the first (original) part is executed. If he updates from 5.x-1.x to 6.x-1.x the alternative part matching Drupal 6's core database schema is used. If there is no conditional code, all 5.x-1.x users have to update to 5.x-2.x first before switching to Drupal 6 and image 6.x-1.x. Many users will still have installed 5.x-1.x, because there is no final image 5.x-2.x yet.

If you have any idea how to cleanly solve this issue without the VERSION condition I'd be happy to update the patch.

The WHERE EXISTS clause is standard SQL and works with MySQL 5.0 and PostgreSQL 8.1 on my test system.

#12

drewish - August 17, 2008 - 23:13

great i just wasn't sure where that was defined. i'm super short on time but if i can get a few people to test this i'd love to get it committed. in the mean time i've updated the 6.x release notes to tell the users to upgrade to 5.x.-2.x before going to 6.x.

#13

nishit - August 31, 2008 - 04:51

great
The patch is working perfectly.

Thanks guys for the wonderful job.

#14

heshanmw - September 11, 2008 - 08:53

You should run the update.php file to complete the process. In my scenario I have to run the update.php file.

#15

jandd - November 22, 2008 - 10:10
Status:needs work» postponed (maintainer needs more info)

My patch works fine for users upgrading from Image 5.x-1.x to 6.x-1.x but as I understand it will not get blessed by the module's maintainer because of the distinction between an upgrade from 5.x-1.x to 6.x-1.x and 5.x-2.x to 6.x-1.x (or an older 6.x-1.x to a newer 6.x-1.x). I don't know what to do in this case. Is there any way to tell users: If you want to upgrade from 5.x-1.x to 6.x-1.x (without upgrading to 5.x-2.x-dev first), you need this patch but it will not be included in the normal 6.x code because of ...? I think that many users will upgrade from the stable (read 5.x-1.x) series of the Image module to the 6.x-1.x version when they upgrade their Drupal site to Drupal 6 and I'm wondering how we could properly guide these users.

Any thoughts from Image module's maintainer(s)?

#16

jandd - November 22, 2008 - 10:24
Assigned to:jandd» Anonymous

#17

sun - January 14, 2009 - 00:22
Status:postponed (maintainer needs more info)» needs work

Trying to get this back into my tracker.

#18

sun - January 17, 2009 - 23:59
Version:6.x-1.0-alpha2» 6.x-1.0-alpha4
Status:needs work» needs review

Please test attached patch.

AttachmentSize
image-HEAD.image-upgrade.patch 1.7 KB

#19

sun - March 5, 2009 - 22:59
Title:Error: Unknown column 'f.nid' in 'field list' query» 6.x upgrade error: Unknown column 'f.nid' in 'field list' query

#20

sun - March 6, 2009 - 02:36
Status:needs review» fixed

Committed.

#21

System Message - March 20, 2009 - 02:40
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

#22

joachim - April 23, 2009 - 06:42

Just found this...
Is this issue the reason for the upgrade warning on the project page?
If so, now it's been committed, can we remove that warning, or change it?

#23

sun - April 23, 2009 - 10:17

"Hopefully, yes." ;) We would need to test the upgrade path from D5 with 5.x-1.x to 6.x-1.x to be sure.

#24

harmonica - May 13, 2009 - 10:07

Hi,

I made the upgrade from 5.x-1.x to 6.x-1.x yesterday and encountered this very problem. My database backup did not seem to want to work for me, so I tried stdbrouw's fix (post #4 above) to get my database back:

INSERT INTO image (nid, fid, image_size) SELECT u.nid, f.fid, f.filename FROM files f LEFT JOIN upload u ON f.fid=u.fid

That worked except for the last five image uploads. I can see the associated files in the images folder with my ftp client, but they do not show on the screen in Drupal. Attempts to rebuild derivatives are unsuccessful, asking for an image to upload.

Also I cannot upload any new images -- the box for the thumbnail is drawn (with no image) and then quickly disappears. The alt-text for the thumbnail is displayed and clickable. There is no large image displayed. I have triple-checked the database file_directory_path and image_default_path and verified their settings (Administer>File System>File System Path and Images>Image File Settings>Default Image Path) as well as clearing the cache. No Luck.

I have a feeling that my database is still not right. The 'image' structure looks like this:

Field Type Null Default
nid int(10) No 0
fid int(10) No 0
image_size varchar(32) No

Indexes:
Keyname Type Cardinality Field
PRIMARY PRIMARY 607 nid
image_size
fid INDEX 607 fid

As you can probably tell, my mySQL & programming knowledge is limited. Any ideas are appreciated.

Nick

 
 

Drupal is a registered trademark of Dries Buytaert.