不要怂,就是干,撸起袖子干!

Commit 07998023 by overlookmotel Committed by Jan Aagaard Meier

Foreign key constraint error

1 parent 155e8adc
......@@ -62,6 +62,24 @@ module.exports = (function() {
parent: err
});
case 1451:
match = err.message.match(/FOREIGN KEY \(`(.*)`\) REFERENCES `(.*)` \(`(.*)`\)(?: ON .*)?\)$/);
return new sequelizeErrors.ForeignKeyConstraintError({
fields: null,
index: match[3],
parent: err
});
case 1452:
match = err.message.match(/FOREIGN KEY \(`(.*)`\) REFERENCES `(.*)` \(`(.*)`\)\)$/);
return new sequelizeErrors.ForeignKeyConstraintError({
fields: null,
index: match[1],
parent: err
});
default:
return new sequelizeErrors.DatabaseError(err);
}
......
......@@ -122,6 +122,26 @@ error.UniqueConstraintError = function (options) {
this.index = options.index;
};
util.inherits(error.UniqueConstraintError, error.DatabaseError);
/**
* Thrown when a foreign key constraint is violated in the database
* @extends DatabaseError
* @constructor
*/
error.ForeignKeyConstraintError = function (options) {
options = options || {};
options.parent = options.parent || { sql: '' };
error.DatabaseError.call(this, options.parent);
this.name = 'SequelizeForeignKeyConstraintError';
this.message = options.message;
this.fields = options.fields;
this.value = options.value;
this.index = options.index;
};
util.inherits(error.ForeignKeyConstraintError, error.DatabaseError);
/**
* The message from the DB.
* @property message
......
......@@ -269,6 +269,13 @@ module.exports = (function() {
sequelizeErrors.UniqueConstraintError;
/**
* Thrown when a foreign key constraint is violated in the database
* @see {Errors#ForeignKeyConstraintError}
*/
Sequelize.prototype.ForeignKeyConstraintError = Sequelize.ForeignKeyConstraintError =
sequelizeErrors.ForeignKeyConstraintError;
/**
* Returns the specified dialect.
*
* @return {String} The specified dialect.
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!