How can I ensure migration YAML files execute in specified dependency order?

EDIT: To Answer my own question…

I ended up making multiple migration files like this:

  1. Node Type A Part 1 (most fields migrated except the ones that need to reference Node Type B)
  2. Node Type B
  3. Node Type A Part 2 (now you can add the field referencing Node Type B)
  4. etc.

Here’s a Github link to my finalized set of real-world migration files which illustrate how I broke up my migration into different sequential parts. Good luck!


Original Question:

My Drupal migration yaml files are not being imported in the correct execution order.

I have 8 migration files, most that depend on another file being executed first. I’m using a Google Spreadsheet as the source, and targeting Drupal 8.9+. I have tagged all my dependencies, and all was going well with my test imports (using drush migrate:import --tag="Rooster Business") and the corresponding rollback commands. But at some point, after adding a few fields, the migrations began to fail because they were being executed out of order (particularly my business_locations and business_offers migrations).

Here’s the exact error:

[error]  Migration rooster_node_business_offers did not meet the requirements.  Missing migrations rooster_node_business_location. requirements: rooster_node_business_location. 

The new fields themselves don’t fail, so it’s not that (I wouldn’t think). I think I have correctly set up the dependencies in all the files, but they are NOT being respected (at least not completely).

I have tried the following:

  • Alphabetizing all the migration id’s and filenames (to order them by desired import execution order).
  • Dropping all migration tables from the database and doing full cache refresh
  • Changing the last file I want executed (rooster_node_business_offers) to use "optional" dependencies instead of "required." (This causes the failure to go away, but then some of the desired field values are missing from the migration).
  • Uninstalling and reinstalling the entire custom migration module.
  • I’ve tried just migrating the "last" migration with drush migrate:import rooster_node_business_offers --execute-dependencies command which should in theory execute all the files in order as they all depend in a chain on each other. No dice. I get the same error: [error] Migration rooster_node_business_offers did not meet the requirements...

None of these attempts have solved the problem. I have a theory that it has something to do with the fields names of the sources (because I think I may have changed a few of them, and have definitely added quite a few). But that still doesn’t account for why the migrations are not respecting the dependency order.

Bottom line: I have two questions:

  1. Why are the last two migration files (rooster_node_business_location & rooster_node_business_offers) not being executed in order by dependency (and how can I fix this)?
  2. If that is not an easy to answer question, what is the logic of the "default" ordering, and how can I game that logic so I can still get my migration files to execute in the desired order?

Here is the order I’d LIKE to have the migrations to execute in:

rooster_file_bg_photo rooster_file_logo rooster_users rooster_file_logo_to_media rooster_file_bg_photo_to_media rooster_node_parent_business rooster_node_business_location rooster_node_business_offers 

And here is the order that they are actually being migrated in (same as the order displayed after entering the drush ms command:

  Rooster (Rooster)   rooster_file_bg_photo            Idle   Rooster (Rooster)   rooster_file_logo                Idle   Rooster (Rooster)   rooster_users                    Idle   Rooster (Rooster)   rooster_file_logo_to_media       Idle   Rooster (Rooster)   rooster_file_bg_photo_to_media   Idle   Rooster (Rooster)   rooster_node_parent_business     Idle   Rooster (Rooster)   rooster_node_business_offers     Idle   Rooster (Rooster)   rooster_node_business_location   Idle 

I’ve made a repository of my exact migration files (and I’ve only redacted the Google Spreadsheet URLs). Here are all the migration files on Github.

Thanks in advance for your help!

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

How can I ensure migration YAML files execute in specified dependency order?

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.