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
Comment #1
Andrey Zakharov commentedimplement method YourMigration::prepareRow
Comment #2
alanburke commentedThanks Andrey!
I implemented a cleanup function in my base class
and I call that within prepare_Row for each migration.
Comment #4
drclaw commentedI don't think this solution works anymore... I'm using migrate-7.x-2.5 and I'm still getting fields populated with empty values. (e.g.
$node->field_name['und'][0]['value'] == 0). I took a look at Migration::applyMappings() and it looks like the destination object has a field value set regardless of whether or not it's corresponding source field is set. I could be wrong though... has anyone else got this method above to work?Comment #5
chrisakeley commentedThis solution did not work for me, either. Even when using unset() in prepareRow, migrate created blank rows in the field_data_XX table for text fields. It looks like using removeFieldMapping DOES work, however. For example:
if (!strlen($row->my_text_field) $this->removeFieldMapping('my_text_field');Comment #6
drclaw commentedAh, I see. Thanks for mentioning that!
Comment #7
mikeryanPlease don't reopen long-closed issues - look for a relevant open issue (consider if #1792894: Set configured defaults for empty fields applies) or open a new issue.
Thanks.
Comment #8
ronino commentedNone of the above solutions works for me with version 2.5. What works for me instead in prepareRow() is to assign an empty array to those fields:
Comment #9
pmkanse commentedThanks @Ronino, it works!!!!