0

I have a rather complex database schema using foreign key constraints. This database schema will be accessed with REST services.

Should REST or the database be responsible for referential integrity? Is it bad practice to have foreign keys constraints in the database when the entities are updated / deleted via REST?

1 Answer 1

4

Should REST or the database be responsible for referential integrity?

Both:

  • DB should have proper constraints.
  • API should have validation rules which reflect those constraints (e.g. "role_id cannot be null on user object"), check those, and provide meaningful error messages when they are violated.

Is it bad practice to have foreign keys constraints in the database when the entities are updated / deleted via REST?

No, it is a requirement if you want to keep your data consistent.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.