4

I'm trying to set up my migration mapping to transfer over some custom fields that were created by installed modules, but I'm unsure how to define that in map.xml

For example, I have the field sales_flat_order.onestepcheckout_customercomment which I'd like to move to sales_order.onestepcheckout_customercomment. So I include the following in my map.xml:

    <move>
        <field>sales_flat_order.onestepcheckout_customercomment</field>
        <to>sales_order.onestepcheckout_customercomment</to>
    </move>

But the migration tool doesn't know the destination field sales_order.onestepcheckout_customercomment and so fails to map it.

My guess is there is some <transform> block I should be using, but I can't find any documentation detailing the different transform handlers.

1
  • you need to create such column into magento 2 db manually or using some script. Commented Nov 14, 2017 at 19:06

2 Answers 2

6

To migrate custom fields to Magento 2, the custom field column must map to an existing Magento 2 table column. If the custom field column does not already exist in the Magento 2 table then you can't map the custom field into Magento 2.

Here's an example (this is from the default Magento 2 map file). In the cms_page table from Magento 1, the column root_template exists, but that column is not available in the Magento 2 cms_page table. Thus, custom field mapping is done using the tags below. Here the custom field root_template is mapped onto page_layout so that all values of root_template transfer to the page_layout field of the cms_page Magento 2 table.

<move>
    <field>cms_page.root_template</field>
    <to>cms_page.page_layout</to>
</move>

In your case, onestepcheckout_customercomment is a custom field that is not available in the default sales_flat_order table, so you can only map that field onto Magento 2 if you have created a new field inside the Magento 2 sales_order table. Otherwise you can't do the mapping.

Your mapping tag is in the right direction, but mapping is not possible because the sales_order table in Magento 2 doesn't contain the onestepcheckout_customercomment field.

Your code inside map.xml

<move>
        <field>sales_flat_order.onestepcheckout_customercomment</field>
        <to>sales_order.onestepcheckout_customercomment</to>
</move>

would work if the sales_order table had the onestepcheckout_customercomment field. You don't need a transform tag for basic field mapping.

Thanks.

2
  • Does that mean I need to manually update the table structure to add the new field? Is there no method for add custom fields to existing tables through the migration tool?
    – ben
    Commented Feb 18, 2016 at 17:00
  • There are not custom tool for migrate custom field using migration tool. you have to add custom field using Setup/Upgradeschema file or manually add field to table. Commented Feb 19, 2016 at 4:57
4

You should create (preferably by schema setup script) columns in the relevant table where you want the custom fields to be in.

The migration tool doesn't create new columns.

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.