mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-26 22:00:16 +08:00
Foreign key constraint symbol names must be unique in a database. To avoid violation errors the "Copy table" dialog should just leave the CONSTRAINT clause out from the CREATE TABLE code. In that case MySQL auto creates a valid name on demand. See http://www.heidisql.com/forum.php?t=6086
This commit is contained in:
@ -88,7 +88,7 @@ type
|
||||
Modified, Added, KeyNameWasCustomized: Boolean;
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
function SQLCode: String;
|
||||
function SQLCode(IncludeSymbolName: Boolean): String;
|
||||
end;
|
||||
TForeignKeyList = TObjectList<TForeignKey>;
|
||||
|
||||
@ -2560,11 +2560,15 @@ begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
function TForeignKey.SQLCode: String;
|
||||
function TForeignKey.SQLCode(IncludeSymbolName: Boolean): String;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
Result := 'CONSTRAINT '+TMySQLConnection.QuoteIdent(KeyName)+' FOREIGN KEY (';
|
||||
Result := '';
|
||||
// Symbol names are unique in a db. In order to autocreate a valid name we leave the constraint clause away.
|
||||
if IncludeSymbolName then
|
||||
Result := 'CONSTRAINT '+TMySQLConnection.QuoteIdent(KeyName)+' ';
|
||||
Result := Result + 'FOREIGN KEY (';
|
||||
for i:=0 to Columns.Count-1 do
|
||||
Result := Result + TMySQLConnection.QuoteIdent(Columns[i]) + ', ';
|
||||
if Columns.Count > 0 then Delete(Result, Length(Result)-1, 2);
|
||||
|
Reference in New Issue
Block a user