fixes #2400 - clean up tests so there are no orphaned foreign keys
fixes #2400 add foreign keys to database migrations