The parent key (in TOOL_CONTRACTS) is not found for the values being inserted in TOOL_CONTRACT_LINES. The values for CONTRACT_ID in TOOL_CONTRACT_LINES are: 'AZ15', 'AZ16', 'AZ17', etc. but the values present in TOOL_CONTRACTS are 'Az15', 'Az16', 'Az17', etc. (the character 'z' is in lower case). Make this correction and the script will work fine.