Fix foreign key check