Resolved the problem of adding foreign key constraints for dynamically created tables