fixed some bug about foreign key