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
bundle: blog
tonode_type: blog
and flush all caches.