Download & Extend

Importing blank values

Project:Migrate
Version:7.x-2.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

On some of my migrations, the source table is missing values for some of the fields.
When migrating into Drupal, it still imports that missing value.
So some fields have a label, but no value.
If I even just edit and save the node (with no other changes), the blank value is removed [and the label no longer shows].

Is there any way to avoid these 'Phantom Values'?

Comments

#1

implement method YourMigration::prepareRow

public function prepareRow($row) {
      if (empty($row->default_zero_field))
         unset($row->default_zero_field);
}

#2

Status:active» fixed

Thanks Andrey!
I implemented a cleanup function in my base class

<?php
     
public function __prepareRow($current_row) {
        foreach(
$current_row as $field=>$value){
          if (empty(
$value) && $value !="0"){
             unset(
$current_row->$field);
          }
        }
      }
?>

and I call that within prepare_Row for each migration.

#3

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nobody click here