0

I run migrations from CSV using Migrate Source CSV, Migrate Plus and Migrate Tools modules and it works fine.
The result of one of these migration is a custom entity which key is a 'id' field that has the 'AUTO_INCREMENT' property in the database.
Here is my migration_contractssubscriptions.yaml

id: migration_contractssubscriptions
migration_group: null
label: 'Contract Subscriptions migration from CSV'
source:
  plugin: csv
  path: /mypathto/migration_ContractsSubscriptions.csv
  delimiter: ';'
  enclosure: '"'
  header_row_count: 1
  keys:
    - id
process:
  id: id
  contract_id: contract_id
  member_id: member_id
  sharedwith_member_id: sharedwith_member_id
  comment: comment
  quantity01: quantity01
  quantity02: quantity02
  quantity03: quantity03
  quantity04: quantity04
  owner_id:
    plugin: default_value
    default_value: 1
destination:
  plugin: 'entity:contract_subscription'

I'd like to get rid of 'id' in my csv file and let the migration process handle the value of the resulting id.
I tried to remove keys: - id and id: id but I get an error...
How can I achieve that?

2
  • I assume id is the primary key of your custom entity, so simply removing process: id: id should work. Do not remove or change fields from source: keys: in production - Migrate's internal mapping table would get out of sync. If you change the source keys, rollback and drop the mapping table first. Look for migrate_map_FOOBAR tables in your DB. – Hudri Dec 6 '19 at 16:29
  • Once removed id: id from process: I have this error: [error] La migration a échoué avec l'exception de plugin source : id is defined as a source ID but has no value. – gbmapo Dec 6 '19 at 22:06
0

I finally understood that keys in source is the way to make each row of the csv file unique. It may be anything.
So I changed to:

  keys:
    - contract_id
    - member_id

I removed id: idfrom processand it works!
The value of id field in the database is properly auto-incremented.

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.