Database restrictions are not required anymore than wearing seat belts in your car. You can get around anything you like and everything will work just fine until the problem comes up. A seat belt (restriction) allows you (data) to be safe.
Therefore, it is strongly recommended that you create restrictions to ensure data integrity at the database level, since it is very likely that 1) you will interact with the database at some point outside of Rails, and 2) you will make an error in your code that causes invalid data.
Database restrictions can be more useful, but it saves a lot of work, especially when your code can make assumptions about data and don't have to do tons of validation checks.
The reason ActiveRecord does not support foreign keys out of the box is because it is designed for database agnostic, and foreign keys are not universally supported by all database systems.
Tilendor Apr 07 2018-10-10T00: 00Z
source share