Migrating data from one org to another org is not an easy job, especially with Child-Parent relationship objects. When we move a small set of records, yes, we can do it by creating the records one by one. What if we have thousands of records? We need to migrate exact parent records with its children. There are several methods to do so; however, I only discuss the Data Loader.
Suppose I have an Master-Detail relationship below:

- Target Org: Create an external Id field Text(18); this will be used to store the record id from the original Org.

- Now export data using Data Loader to export Number records.


- We can export all the children records at this point. You can notice that the Number__c in Draw object is Id from Number object.

- At this stage, we perform import data to parent object first which is Number object. Map the Id field of Original Org to External_ID of Target Org.

- When querying the Id / External ID from target org, you can see we have a mapping pair of new id and old id.

- We are going to import the children using upsert method. Why upsert not insert? Because with upsert, we can map the of Parent of original records to new External_Id.


- Remember to map the parent id with the external Id we have.

- We have children records map to parent records exactly what in original org.
