add foreign key support, finish debug