Fix null foreign keys handling