The Easiest D7 to D9 Image Migration Fix

Created on 30 November 2022, over 1 year ago
Updated 3 October 2023, 9 months ago

Problem/Motivation

After migration the images(files) are in the public folder, but not inside the nodes.
I tried this module to fix the issue, but it wouldn't work with D9.
After looking into some other solutions I decided to check the tables in the database.
There are 2 tables, that are connected to this problem: file_usage and file_managed
By just copying data in MySQL with SQL from d7 database to d9 I was able to fix images in this "quick and dirty" way:

# file_usage tables have exactly the same fields. d7 and d9 are the names of databases. SQLs executed in SQLyog.
INSERT INTO d9.file_usage (fid, module, `type`, id, `count`)
SELECT fid, module, `type`, id, `count`
FROM d7.file_usage;

# file_managed table in D9 has a few extra fields: UUID, langcode and CHANGED.
# UUID field that was just inserted the same fid value in it.
INSERT INTO d9.file_managed (fid, UUID, langcode, uid, filename, uri, filemime, filesize, STATUS, created, CHANGED)
SELECT fid, fid, "en", uid, filename, uri, filemime, filesize, STATUS, TIMESTAMP, TIMESTAMP
FROM d7.file_managed;

After this please still verify that your images are now available inside your nodes.

Hope it would help someone as well, thanks.

πŸ’¬ Support request
Status

Active

Component

Miscellaneous

Created by

πŸ‡¨πŸ‡¦Canada gennadiy

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¨πŸ‡¦Canada arne.olafson

    The first one ran perfectly, with thousands of rows affected, but the second one gave me an error:

    Duplicate entry '1' for key 'PRIMARY'
    

    It turned out that it was because I had uploaded a logo and favicon file. Manually deleting the records on the d9.file_managed table made it run just fine and I now have images migrated to my d9 fields. Thank you!!

Production build 0.69.0 2024