I have multiple CSV files in different folders. The folder names are the node ids. And each folder contains its own CSV file. Now I want to loop these directories and import from the CSV files in one migration class but it only migrate from the last CSV file.

Here is my code

class MigrateNodes extends Migration {
  public function __construct($arguments) {
    $columns[0] = array('Number', 'Number');
    $columns[1] = array('Title', 'Title');
    $columns[2] = array('Description', 'Description');
    //The Description of the import. This desription is shown on the Migrate GUI
    $this->description = t('Import lots from excell file ');
    $nids = db_select('node', 'n')
        ->fields('n', array('nid'))
        ->condition('n.type', 'type')
    foreach ($nids as $nid) {
   $path = $nid . "/nodes.csv";
      //The Source of the import
      $this->source = new MigrateSourceCSV($path', $columns, array('header_rows' => 1));
      if ($this->source) {
        $this->destination = new MigrateDestinationNode('lot');
        $this->map = new MigrateSQLMap(
            $this->machineName, array(
          "Number" => array(
            'type' => 'int',
            'unsigned' => TRUE,
            'not null' => TRUE,
            'alias' => 'import'
            ), MigrateDestinationNode::getKeySchema()
        //Field ampping
        $this->addFieldMapping('title', 'Title');
        $this->addFieldMapping('field_lot_description', 'Description');

The Number field is unique. Any one knows what I am doing wrong?

1 Answer 1


I have solved it. Just place the following line after the field mappings if it is the import process.

  • this is also covered in the Migrate Examples module. The baseball example uses multiple csv files as the datasource.
    – dreftymac
    Oct 5, 2015 at 23:00

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.