Fixing foreign key constraint in agent insertion.
Enforcing FK constraints.
fixing test case.