How to Migrate Users from Drupal 7 to Drupal 10

How to Migrate Users from Drupal 7 to Drupal 10 (With Images)

Migrating user data from Drupal 7 to Drupal 10 is one of the most common challenges developers face. This guide explains a clean and practical approach to migrate users along with their profile images.

Why Drupal 7 to Drupal 10 Migration Is Important

Drupal 7 has reached end of life. Upgrading to Drupal 10 ensures better security, performance, and long-term support.

Common Challenges During User Migration

  • User passwords compatibility
  • Profile images not displaying
  • File path mismatches
  • Role mapping issues

Step 1: Copy User Images

Copy the files directory from Drupal 7:

sites/default/files

Paste it into Drupal 10:

web/sites/default/files

Step 2: Create Users Programmatically

Drupal 10 does not support direct entity loading from Drupal 7. You must create users manually using PHP.

use Drupal\user\Entity\User;

$user = User::create([
  'name' => 'john_doe',
  'mail' => 'john@example.com',
  'status' => 1,
]);
$user->save();

Step 3: Attach Profile Image

Load the image file and attach it to the user entity.

use Drupal\file\Entity\File;

$file = File::create([
  'uri' => 'public://pictures/john.jpg',
  'status' => 1,
]);
$file->save();

$user->set('user_picture', [
  'target_id' => $file->id(),
]);
$user->save();

Final Thoughts

Manual migration gives you full control over user data. However, for large websites, Drupal Migrate API is recommended.

If you need help with Drupal, Laravel, or PHP solutions, stay connected with Developer Sahayak.


Author: Backend Developer (Laravel | Drupal | PHP)

0 Comments