An error “Error: Field is not writeable” will occur if you try modifying a Master-Detail relationship field in Salesforce Apex code. So how can we fix it? Maybe using the clone method to insert&delete is the only way, as the following apex code : Reference：Apex System SObject Clone Enjoy It!