Migrations: How to update existing paragraphs?

I’m writing migrations to import source data as paragraphs.

Here is the main migration (which is working):

id: resource_chapter_section_text label: Import content from the resource.body column in the source database as chapter_section_text paragraphs. migration_group: redacted_web source:   plugin: resource_chapter_section_text   key: migrate_web process:   # a real value will be placed here by the resource_chapter_section_text_content migration   # we have to do it in a second pass to avoid creating a circular dependency   field_text/value:     plugin: default_value     default_value: 'placeholder'   field_text/format:     plugin: default_value     default_value: 'plain_text' destination:   plugin: entity_reference_revisions:paragraph   default_bundle: chapter_section_text dependencies:   enforced:     module:       - redacted_migration 

Note that field_text is being populated with a placeholder value. That’s because the source data for that field needs to be transformed in certain ways before I can import it. In order to avoid a circular dependency, this transformation must be done after all chapter_section_text paragraphs have been imported.

So, I’m trying to write a second migration, which will do a second pass over the same source table, and will update the paragraphs that were created by the first migration. Here is that second migration:

id: resource_chapter_section_text_content label: Converts the contents of resource_chapter_section_text paragraphs from pseudo-Markdown to HTML, and updates link URLs. migration_group: redacted_web source:   plugin: resource_chapter_section_text_content   key: migrate_web process:   id:     plugin: migration_lookup     migration: resource_chapter_section_text     source: section_id   field_text/value: content_converted   field_text/format:     plugin: default_value     default_value: 'full_html' destination:   plugin: entity_reference_revisions:paragraph   default_bundle: chapter_section_text   overwrite_properties:     - field_text/value     - field_text/format migration_dependencies:   required:     - resource_chapter_section_text     - collection_term     - document_node     - theme     - resource dependencies:   enforced:     module:       - redacted_migration 

As you can see, I’m specifying the existing paragraph ID, and using destination.overwrite_properties to specify the fields to be updated.

I’ve successfully used the same technique in another migration to update existing nodes. However, it’s not working here. Migrate seems to be trying to create new paragraphs instead. I get this error:

[error]  DrupalCoreDatabaseIntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '3829' for key 'PRIMARY': INSERT INTO "paragraphs_item" ("id", "revision_id", "type", "uuid", "langcode") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4); 

Is it possible to do this with paragraph entities? Am I doing something wrong?


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

Migrations: How to update existing paragraphs?

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.