Fix foreign key reference
Fix member checking query