Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: cannot create nor edit foreign keys from schema visualiser (#44190)

Gildas Garcia16ec2c09c583
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx
index 563580f5475..3426c247772 100644
--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx
@@ -364,6 +364,7 @@ export const ColumnEditor = ({
>
<FormSectionContent loading={false} className="lg:!col-span-8">
<ColumnForeignKey
+ tableId={selectedTable.id}
column={columnFields}
relations={fkRelations}
closePanel={closePanel}
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnForeignKey.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnForeignKey.tsx
index 22fbdeb0b26..eeca2f8e42c 100644
--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnForeignKey.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnForeignKey.tsx
@@ -1,10 +1,10 @@
import { useParams } from 'common'
-import { useState } from 'react'
-import { Button } from 'ui'
-
import { useForeignKeyConstraintsQuery } from 'data/database/foreign-key-constraints-query'
import { useTableEditorQuery } from 'data/table-editor/table-editor-query'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
+import { useState } from 'react'
+import { Button } from 'ui'
+
import { ForeignKeySelector } from '../ForeignKeySelector/ForeignKeySelector'
import type { ForeignKey } from '../ForeignKeySelector/ForeignKeySelector.types'
import type { ColumnField } from '../SidePanelEditor.types'
@@ -12,6 +12,7 @@ import { ForeignKeyRow } from '../TableEditor/ForeignKeysManagement/ForeignKeyRo
import { checkIfRelationChanged } from '../TableEditor/ForeignKeysManagement/ForeignKeysManagement.utils'
interface ColumnForeignKeyProps {
+ tableId?: number
column: ColumnField
relations: ForeignKey[]
closePanel: () => void
@@ -20,6 +21,7 @@ interface ColumnForeignKeyProps {
}
const ColumnForeignKey = ({
+ tableId,
column,
relations,
closePanel,
@@ -29,7 +31,6 @@ const ColumnForeignKey = ({
const { id: _id } = useParams()
const [open, setOpen] = useState(false)
const [selectedFk, setSelectedFk] = useState<ForeignKey>()
-
const { data: project } = useSelectedProjectQuery()
const { data } = useForeignKeyConstraintsQuery({
projectRef: project?.ref,
@@ -41,7 +42,7 @@ const ColumnForeignKey = ({
const { data: table } = useTableEditorQuery({
projectRef: project?.ref,
connectionString: project?.connectionString,
- id,
+ id: tableId ?? id,
})
const formattedColumnsForFkSelector = (table?.columns ?? []).map((c) => {
return {