I came upon this error when I assigning the custom object to the master standard object.
Invoice__c inv = new Invoice__c();
inv.Account__c = accountId;
Then I get this error.
Field is not writable : Invoice__c.Account__c
The fix was actually easy. I just rewrote it to assign the master id on instantiating the child object.
Invoice__c inv = new Invoice__c(Account__c = accountId);
Hope somebody finds this useful.