fixed issue of foreignkey constraints and add testing example