diff --git a/src/components/EditorCanvas/Canvas.jsx b/src/components/EditorCanvas/Canvas.jsx index 44ea706..50daf0d 100644 --- a/src/components/EditorCanvas/Canvas.jsx +++ b/src/components/EditorCanvas/Canvas.jsx @@ -400,7 +400,11 @@ export default function Canvas() { }); }; - const handleGripField = () => { + const handleGripField = (field) => { + if (!field.primary && !(field.notNull && field.unique)) { + Toast.info(t("cannot_fk")); + return; + } setPanning((old) => ({ ...old, isPanning: false })); setDragging({ element: ObjectType.NONE, id: -1, prevX: 0, prevY: 0 }); setLinking(true); diff --git a/src/components/EditorCanvas/Table.jsx b/src/components/EditorCanvas/Table.jsx index 1e656f9..19f235f 100644 --- a/src/components/EditorCanvas/Table.jsx +++ b/src/components/EditorCanvas/Table.jsx @@ -317,10 +317,10 @@ export default function Table(props) { onPointerDown={(e) => { if (!e.isPrimary) return; - handleGripField(index); + handleGripField(fieldData); setLinkingLine((prev) => ({ ...prev, - startFieldId: index, + startFieldId: fieldData.id, startTableId: tableData.id, startX: tableData.x + 15, startY: diff --git a/src/i18n/locales/en.js b/src/i18n/locales/en.js index 81c903a..0dad5a4 100644 --- a/src/i18n/locales/en.js +++ b/src/i18n/locales/en.js @@ -146,6 +146,7 @@ const en = { relationship_deleted: "Relationship deleted", type_deleted: "Type deleted", cannot_connect: "Cannot connect, the columns have different types", + cannot_fk: "Cannot create foreign key from this field", copied_to_clipboard: "Copied to clipboard", create_new_diagram: "Create new diagram", cancel: "Cancel",