Fixes the case of insert into table with foreign fields