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