2

I'm working on a custom migration from Drupal 6 to Drupal 8. Some of the content types have a field used for file attachments. In Drupal 8 this field has the internal name field_attachments.

When I run the migration that connects the files to the nodes, I get the error:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title' cannot be null: INSERT INTO {node_field_data} (nid, vid, type, langcode, status, uid, title, created, changed, promote, sticky, default_langcode, revision_translation_affected) 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); Array ( [:db_insert_placeholder_0] => 2064 [:db_insert_placeholder_1] => 3019 [:db_insert_placeholder_2] => forum [:db_insert_placeholder_3] => en [:db_insert_placeholder_4] => 1 [:db_insert_placeholder_5] => 0 [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => 1558576761 [:db_insert_placeholder_8] => 1558576761 [:db_insert_placeholder_9] => 0 [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => 1 [:db_insert_placeholder_12] => 1 ) (/app/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php:847)

The YAML file I'm using for this part of the migration is called migrate_plus.migration.custom_upload.yml and it's content is:

langcode: en status: true dependencies: { } id: custom_upload class: Drupal\migrate\Plugin\Migration field_plugin_method: alterFieldInstanceMigration cck_plugin_method: null migration_tags: - 'Drupal 6' - Content migration_group: custom label: 'File uploads' source: plugin: d6_upload process: nid: - plugin: get source: nid vid: - plugin: get source: vid langcode: - plugin: user_langcode source: language fallback_to_site_default: true type: - plugin: get source: type field_attachments: - plugin: sub_process source: upload process: target_id: plugin: migration_lookup migration: custom_file source: fid display: plugin: default_value default_value: 1 description: description destination: plugin: 'entity:node' migration_dependencies: required: - custom_file - custom_article - custom_forum

From the error message, it appears that Drupal is trying to create a node; even though, I'm actually running the custom_upload migration after I ran the migration of all nodes.

I have migrated the nodes and the files already and I can see all the nodes in the database as well as the files in their directory and the database.

What am I missing?

2

Your custom_upload migration is trying to create nodes; the custom_upload migration is taking a d6_upload source plugin:

source:
  plugin: d6_upload

...and mapping it to a node:entity destination plugin:

destination:
  plugin: 'entity:node'

Since the d6_upload source doesn't have a title field to map to the node:entity field in the process definition of your migration, the migration fails as it tries to insert a titleless node.

You need update your node migration. If your node/file migrations are working, the node migration should have a process.field_attachments yml property to map field_attachments.target_id to the fid property from your custom_file migration.

  • Hi Shawn, thank you for answering. You're helping me see the light at the end, but I'm not getting it quite yet. – GoingDrupal May 24 at 11:59
  • I can confirm that the node and file migrations are working. The YAML file above, is basically a slightly modified copy of core/modules/file/migrations/d6_upload.yml I expected that plugin: 'entity:node' would update the node entity (not create a new one) because the same file has a field_attachments that uses a plugin: sub_process. You mentioned that the node migration should have a process.field_attachments yml property. How would that look like? That's where I'm still lost. Do you have a snippet of code or could you point me somewhere? – GoingDrupal May 24 at 12:15
2

Every content type migration creates its own mapping table.

I got a clue from how the taxonomy terms are migrated. The trick was to tell Drupal where to look for the nid.

I replaced:

process:
  nid:
    -
      plugin: get
      source: nid
  vid:
    -
      plugin: get
      source: vid

with...

process:
  nid:
    -
      plugin: migration_lookup
      migration:
        - custom_article
        - custom_forum
      source: nid
    -
      plugin: skip_on_empty
      method: row

... and now it works.

By listing the internal names of my two content types, Drupal was able to figure out what node mapping table should be used.

Note that I removed the vid: block with the replacement. I'm not importing node revisions and therefore, I'm not expecting that this will affect anything in my case.

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.