I've recently upgraded a site from a CCK-riddled D6 to D7. I'm pretty much up and running, but I need to migrate my file attachments (they're all in the database, but not appearing on any nodes). I tried the D7 module CCK/migrate module, but it just says "There is no D6 field information in this database.".
To try to work around this, I had a poke about in the database. I found all my file attachments in the content_field_file table. A bit of a funky insert...select later, and I'd copied that data to the field_data_field_attachments table. The thing is, these attachments don't show on nodes.
My question is: What (other) database tables are involved in getting an attachment to appear on a node? I've had a play with DB logging in the devel module, but didn't find anything useful. I tried looking in the Content Migrate module, but no joy there either. Anyone know anything more about this?
Comments
Duh!
Duh! You need to make sure your files are in the files_managed table (the table "files" is a D6 one, and not used in D7).
The good news is that it's quite easy to migrate from one to the next. Here's some SQL that approximately does it:
Get entries from 'files' into 'files_managed':
insert into file_managed (fid,uid,filename,uri,filemime,filesize,status,timestamp) select fid,uid,filename,concat('public://',substr(filepath,21)), filemime,filesize,status,timestamp from files where filepath like 'sites%';
Get entries from 'content_field_file' to 'field_data_field_attachments':
select @i:=5;
insert into field_data_field_attachments (entity_type,bundle,deleted,language,delta,field_attachments_display,entity_id,revision_id,field_attachments_fid,field_attachments_description) (select 'node','article',0,'und',@i:=@i+1,1,nid,vid,field_file_fid,field_file_data from content_field_file where field_file_fid > 0);
This last SQL doesn't convert the 'description' field from JSON to plain text, so the file names look a bit weird unless you do some very funky SQL to clean it up, or else edit the field_attachment_description column somehow in the 'field_data_field_attachments' table. I used:
trim(trailing '";}' from substr(field_file_data,31))
...in place of field_file_data in the above SQL, but that probably won't work for everyone.
Lastly, I found you also need to populate file_usage:
insert into file_usage (fid,module,type,id,count) select field_attachments_fid,'file','node',entity_id,1 from field_data_field_attachments;
...and I think that's all :-)