fix bugs with migration and foriegn key ids