Set explicit default value "NO ACTION" for ON UPDATE/DELETE clauses when creating a foreign key. Closes #1320

This commit is contained in:
Ansgar Becker
2021-02-27 11:08:57 +01:00
parent 6e053ee640
commit 5204ac54fa
2 changed files with 5 additions and 9 deletions

View File

@ -9537,6 +9537,9 @@ begin
Columns.StrictDelimiter := True;
ForeignColumns := TStringList.Create;
ForeignColumns.StrictDelimiter := True;
// Explicit default action required, since MariaDB and MySQL have different defaults if it's left away, see issue #1320
OnUpdate := 'NO ACTION';
OnDelete := 'NO ACTION';
end;
destructor TForeignKey.Destroy;

View File

@ -2468,8 +2468,6 @@ begin
Key := TForeignKey.Create(DBObject.Connection);
idx := FForeignKeys.Add(Key);
Key.KeyName := 'FK'+IntToStr(idx+1);
Key.OnUpdate := '';
Key.OnDelete := '';
Key.Added := True;
Modification(Sender);
listForeignKeys.Repaint;
@ -2647,14 +2645,9 @@ begin
4: begin
CellText := Key.OnUpdate;
// Both ON UPDATE + DELETE default to "RESTRICT", see http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html
if CellText = '' then
CellText := 'RESTRICT';
end;
5: begin
CellText := Key.OnDelete;
if CellText = '' then
CellText := 'RESTRICT';
// MySQL 8 has a "NO ACTION" default here, which makes any fallback wrong here
end;
5: CellText := Key.OnDelete;
end;
end;