1

I am trying to do data migration from a Drupal 7 site to a Drupal 8 site using drush migration. Example: I am trying to import users which has 5-7 fields and I tried to import fields using:

  • d7_field
  • d7_field_instance

These 2 are importing all fields in Drupal 7 (users, taxonomy, node). How can I restrict this to import only specific entity fields?

2
  • And after migration keeping the user fields and delete all others with a simple foreach in hook_update_N is no option?
    – leymannx
    Jun 28, 2019 at 7:47
  • In the first place itself using drush is there any option to restrict fields?. Because in my D7 site almost 250 fields are there. Can't import all fields and again run hook_update_N() to delete others.
    – Ajay Reddy
    Jun 28, 2019 at 10:21

1 Answer 1

3
+50

You can achieve this via a custom migration module, this way you have full control over what will be migrated, note the bold text:

  • Create the migrations using drush migrate-upgrade --configure-only as discussed in Upgrade Using Drush
  • Make sure you have aconfig/syncdirectory, to which the next step will write
  • Export the migrations using drush config:export
  • Create your custom migration module
  • Copy only the YML files you want to use from the config/sync directory into the config/install directory of your new custom module, editing them to remove the uuid values and to edit the id, group, label, and other values as needed
  • In the config/install directory of your new custom module, make a new migrate_plus.migration_group.your_module.yml file for your new migration group.

from official handbook: https://www.drupal.org/docs/8/upgrade/customize-migrations-when-upgrading-to-drupal-8

You can also rename the fields. Further processing can happen in hook_migrate_prepare_row(), hook_migration_plugins_alter(), or even a custom process plugin.

update

Please note that you will not be exporting configuration from a site and moving it to other site. Config export is a bad name here. Read it as generate migration template.

When you generated your template (aka, exported), you handpick those fields, entities and configuration that you want from all the available generated files, put them in a custom module, say my_custom_mig, enable it, and run it's migration.

4
  • We are trying to do this via drush migration, not with config export. And also I am asking "User" entity as an example here. What if I want to do for an article entity or vocabulary. I can't export the config and import it manually. So I want to do it via drush migration.
    – Ajay Reddy
    Jun 28, 2019 at 10:01
  • 1
    @Ajay Reddy can you please update the question to reflect your requirements? Jun 28, 2019 at 10:11
  • @AjayReddy answer updated.
    – hkoosha
    Jun 28, 2019 at 10:26
  • @hkoosha Thanks for the idea. This is not the exact solution for me but the idea of using hook_migrate_prepare_row() works for me and I did some customizations on this.
    – Ajay Reddy
    Jul 1, 2019 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.