Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 07998023
authored
Sep 04, 2014
by
overlookmotel
Committed by
Jan Aagaard Meier
Sep 13, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Foreign key constraint error
1 parent
155e8adc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
0 deletions
lib/dialects/mysql/query.js
lib/errors.js
lib/sequelize.js
lib/dialects/mysql/query.js
View file @
0799802
...
@@ -62,6 +62,24 @@ module.exports = (function() {
...
@@ -62,6 +62,24 @@ module.exports = (function() {
parent
:
err
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
:
default
:
return
new
sequelizeErrors
.
DatabaseError
(
err
);
return
new
sequelizeErrors
.
DatabaseError
(
err
);
}
}
...
...
lib/errors.js
View file @
0799802
...
@@ -122,6 +122,26 @@ error.UniqueConstraintError = function (options) {
...
@@ -122,6 +122,26 @@ error.UniqueConstraintError = function (options) {
this
.
index
=
options
.
index
;
this
.
index
=
options
.
index
;
};
};
util
.
inherits
(
error
.
UniqueConstraintError
,
error
.
DatabaseError
);
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.
* The message from the DB.
* @property message
* @property message
...
...
lib/sequelize.js
View file @
0799802
...
@@ -269,6 +269,13 @@ module.exports = (function() {
...
@@ -269,6 +269,13 @@ module.exports = (function() {
sequelizeErrors
.
UniqueConstraintError
;
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.
* Returns the specified dialect.
*
*
* @return {String} The specified dialect.
* @return {String} The specified dialect.
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment