0

I am doing a migration as per this example https://www.drupal.org/project/migrate_file_to_media/issues/3118471. Migration and step 1 work fine, I get this error when running step 2. I also tried running the migration with an --update flag (drush mim migd8_blog_media_step2 --update) and get the same error . its trying to do an insert instead of an update. And its trying to insert into the source nid, not the target nid.

Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title'[error]cannot be null: INSERT INTO {​​​​​node_field_data}​​​​​ (nid, vid, type, langcode, status, uid, title, created, changed, promote, sticky, default_langcode, revision_translation_affected, publish_on, unpublish_on) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14); Array ( [:db_insert_placeholder_0] => 22610

This is the id of the source node, not the target The migration file I am using contains the following lines.

# This migration links the newly created media entities with entity reference field on the target bundle.
id: migd8_blog_media_step2
label: blog Media Mapping
source:
  key: migrate
  plugin: d7_node
  node_type: blog_entry
destination:
  plugin: entity:node
  default_bundle: blog
process: 
  nid: nid
  changed: changed
  field_files:
    plugin: file_id_lookup
    source: field_main_image
    migration: migd8_blog_media_step1
    no_stub: true
migration_dependencies:
  optional:
  - migd8_node_blog
  - migd8_blog_media_step1

this is my step 1:

# File to Media Migration configuration for blog Media migration

id: migd8_blog_media_step1
label: blog Media Step 1
migration_group: cncs
source:
  key: migrate
  plugin: media_entity_generator_d7
  entity_type: node
  bundle: blog_entry
  langcode: und
  d7_file_url: 'https://www.nationalservice.gov/sites/default/files/'
  #d7_file_url: 'public://'
  field_names:
    - field_main_image

destination:
  plugin: entity:media

process:
    
  bundle:
    plugin: default_value
    default_value: image

  # Using the alt tag if available, else the file name.
  name:
    plugin: media_name
    source: file_name

  # This process plugin will skip the whole row if a existing media is found.
  existing_media_file:
    plugin: check_media_duplicate
    source: target_id

  # This process plugin will skip the whole row if a duplicate image is found.
  unique_file_id:
    plugin: check_duplicate
    source: target_id
    
  # Map the field 
  
  
  field_media_image/alt: alt
  field_media_image/title: title
  field_media_image/target_id:
    plugin: media_file_copy
    move: FALSE
    reuse: TRUE
    path: 'public://images/'
    source: file_path

  langcode: langcode
   
  uid:
    plugin: default_value
    default_value: 1
`

here is my main migration yml :

id: 

migd8_node_blog
label: Custom node migration from Drupal 7
migration_group: cncs
deriver: Drupal\node\Plugin\migrate\D7NodeDeriver
dependencies:
  enforced:
    module:
      - migd8_node_blog_node
source:
 plugin: migd8_node_blog_node # use custom source plugin
 node_type: blog_entry
destination:
  plugin: entity:node
  bundle: blog
process:
  'path/pathauto':
    plugin: default_value
    default_value: 0 # Disable pathauto.
  'path/alias': alias
  type: 
    plugin: default_value
    default_value: blog
  status: status
  uid: 
    plugin: default_value
    default_value: 1
  title: title
  langcode:
    plugin: static_map
    bypass: true
    source: language
    map:
      und: en
  created: created
  changed: changed
  promote: promote
  field_blog_tags:
    plugin: migration_lookup
    source: field_blog_tags
    migration: migrate_taxonomy
  sticky: sticky
  body:
      plugin: sub_process
      source: body
      process:
        value: value
        summary: summary
        format:
          plugin: default_value
          default_value: full_html
  field_blog_author: field_blog_author        
  field_blog_post_date_: 
    plugin: iterator
    source: field_blog_post_date_
    process:
      value:
        plugin: substr
        source: value
        start: 0
        length: 10

I realize its looking for the source nid in this query , not the target nid Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title'[error]cannot be null: INSERT INTO {​​​​​node_field_data}​​​​​ (nid, vid, type, langcode, status, uid, title, created, changed, promote, sticky, default_langcode, revision_translation_affected, publish_on, unpublish_on) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14); Array ( [:db_insert_placeholder_0] => 22610 22610 is the node id in the source. in the target its a totally different nid

11
  • Change bundle: blog to node_type: blog and flush all caches.
    – No Sssweat
    Oct 22, 2020 at 21:36
  • destination: plugin: entity:node node_type: blog. I still get the same error
    – Diana
    Oct 22, 2020 at 21:53
  • Missing bundle for entity type node [error] (/var/www/html/docroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php:108) migd8_blog_media_step2 Migration - 2133 failed.
    – Diana
    Oct 22, 2020 at 22:01
  • It would be helpful to see a backtrace, to see where your error really comes from .. Install past and make it take over your watchdog entries. There should then be the backtrace for your error ... or give XDEBUG a chance, you'll love it.
    – rémy
    Oct 25, 2020 at 20:53
  • 2
    Just by a quick first look, it seems you're missing the Deriver class ?
    – rémy
    Oct 28, 2020 at 22:29

2 Answers 2

2

As the Migrating nodes doc shows, it needs to be:

destination:
  plugin: entity:node
  default_bundle: blog
8
  • Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: [error] 1048 Column 'title' cannot be null: INSERT INTO {node_field_data} (nid, vid, type, langcode, status, uid, title,
    – Diana
    Oct 22, 2020 at 22:55
  • @Diana does your config/install/migrate_plus.migration.mig_blog_node.yml have title: title under process: just like in the link ?
    – No Sssweat
    Oct 22, 2020 at 23:36
  • If I put in a title it creates new content . It’s doing an insert it should be doing an update at this point . The node already exists just trying to attach the media to it
    – Diana
    Oct 23, 2020 at 0:06
  • What version of Drush, migration_tools, migrate_file_to_media, and migrate_plus are you using? I can't get step1 to work, it always gets ignored.
    – No Sssweat
    Oct 23, 2020 at 8:15
  • @Diana I updated my answer with my best guest since I can't try it myself. You might have to put back the title: title
    – No Sssweat
    Oct 23, 2020 at 8:25
1

i imported the new nodes with the same nid as the old ones using

nid: nid 

in the process that fixed the problem!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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