sequelize/sequelize — pull request #2233 by overlookmotel (2014-09-04 09:52:33+00:00)
Title: Custom error for foreign key constraint violation

Like `UniqueConstraintError`, I thought it'd be good to have a custom error for foreign key constraints.

This PR implements that. Foreign key constraint violations now throw a `ForeignKeyConstraintError` rather than generic `DatabaseError`.

But it's not quite ready for prime time, for the following reasons:

* There are two kinds of foreign key errors: (1) trying to reference a row that doesn't exist and (2) trying to delete/update a row that is referenced from elsewhere. Both of these throw the same `ForeignKeyConstraintError` in my PR. This works for my purposes, but maybe other uses would require them to be differentiated into 2 separate errors?
* I've only implemented it for MySQL. I don't run Postgres, MariaDB or SQLite - maybe someone else could add that? (should be pretty trivial)

NB The test that is failing also fails on the current master. I'll submit a separate issue about that.

Any thoughts?