1

I am trying to learn about importing images with migrations using this tutorial and this custom module (c11n_module). When I install and try to run 'drush ms' I keep getting an error.

In CSV.php line 105: You must declare "ids" as a unique array of fields in your source settings.
                                                                           

The id looks like this:

keys:
  - ID 

The helper thought I found shows this:

ids: 
  id:
    type: integer

However, if I change to this:

ids: 
  keys:
    - ID

I still get the error. I have spent a few hours trying to figure this out. I am assuming it is in the YML file that I have to correct this. Any ideas for solving this issue?

Or am I thinking about it all wrong?

Here is the whole YML:

# Migration file for creating "image" for academic programs.
#
# Detailed explanations for various elements of a migration
# YAML have been provided in migrate_plus.migration.program_data.yml

id: program_image
label: Image associated to academic programs.
migration_group: c11n
migration_tags:
  - academic program
  - file
  - image
# Source.
source:
  plugin: csv
  path: 'public://import/program/program.data.csv'
  header_row_count: 1
  ids: 
    keys:
      - Image file
  # Source field definitions.
  fields:
    Image file: Name of the image file associated with the program.
  constants:
    file_source_uri: public://import/program
    file_dest_uri: 'public://program/image'
# Destination.
destination:
  # We will be creating entities of type "file" this time.
  plugin: 'entity:file'
# Mappings.
process:
  file_source:
    -
      plugin: concat
      delimiter: /
      source:
        - constants/file_source_uri
        - Image file
    -
      plugin: urlencode
  file_dest:
    -
      plugin: concat
      delimiter: /
      source:
        - constants/file_dest_uri
        - Image file
    -
      plugin: urlencode
  filename: Image file
  uri:
    plugin: file_copy
    source:
      - '@file_source'
      - '@file_dest'
# Dependencies.
dependencies:
  enforced:
    module:
      - c11n_migrate

1 Answer 1

1

The way you're currently doing it doesn't look familiar, with keys and the way the fields are mapped; might just be it's a method I haven't come across though.

Either way I've always had success processing CSVs like this:

ids:
  - image_file
fields:
  0:
    name: image_file
    label: Image file

That assumes the first column in the CSV contains the unique image file name.

1
  • THANK YOU! That is exactly what I needed. Still learning yaml and figure it out. Thanks Clive !
    – timwhelan
    Commented Nov 7, 2020 at 12:46

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.