-
Notifications
You must be signed in to change notification settings - Fork 3
Description
When a global collection link is added to Menu, Footer, or PreFooter a database error occurs.
Example in Footer:
DB
ERROR: insert or update on table "_custom_col_link_v" violates foreign key constraint "_custom_col_link_v_parent_id_fk"
DETAIL: Key (_parent_id)=(3) is not present in table "_menu_site_collection_v".
STATEMENT: insert into "_custom_col_link_v" ("_order", "_parent_id", "_path", "id", "custom_collection_id", "label", "_uuid", "block_name") values ($1, $2, $3, default, default, default, $4, default) returning "_order", "_parent_id", "_path", "id", "custom_collection_id", "label", "_uuid", "block_name"
App
ERROR: There was an error while saving a version for the global Footer.
err: {
"type": "DatabaseError",
"message": "insert or update on table \"_custom_col_link_v\" violates foreign key constraint \"_custom_col_link_v_parent_id_fk\"",
"stack":
error: insert or update on table "_custom_col_link_v" violates foreign key constraint "_custom_col_link_v_parent_id_fk"
at /app/node_modules/pg/lib/client.js:545:17
...
"length": 315,
"name": "error",
"severity": "ERROR",
"code": "23503",
"detail": "Key (_parent_id)=(3) is not present in table \"_menu_site_collection_v\".",
"schema": "public",
"constraint": "_custom_col_link_v_parent_id_fk",
"file": "ri_triggers.c",
"line": "2596",
"routine": "ri_ReportViolation"
}
Notes
In Payload v3, when you manually set dbName for a block field, Payload creates shared tables (e.g., _custom_col_link and _custom_col_link_v) for every location that uses that same dbName. Those tables’ foreign keys then need to point to the correct parent(the “versions” table for the specific global/collection field you’re saving).
Because Menu and Footer/PreFooter are different globals, but they all use the same underlying table name (_custom_col_link / _custom_col_link_v), the FK constraint gets wired to one parent type first (in your case it’s pointing to the Menu’s versions parent: _menu_site_collection_v). Then, when you save Footer/PreFooter, the child row tries to reference a parent row in the Menu parent table, which obviously doesn’t exist for Footer/PreFooter—hence:
Key (_parent_id)=(17) is not present in table "_menu_site_collection_v". [error | Txt]
That FK mismatch is what cascades into the second error (Cannot read properties of undefined (reading 'type')) during Payload’s afterRead traversal—the version save failed, leaving the data structure incomplete.
Block slugs in Menu:
Using the same slug (customCollectionLink) in multiple blocks fields within the same global can lead to ambiguity about which block config Payload binds during admin operations—especially when schemas (e.g., dbName) differ.
// Top-level items
{ slug: 'customCollectionLinkTop', dbName: 'menu_custom_col_link', ... }
// Dropdown -> subitems
{ slug: 'customCollectionLinkDropdown', dbName: 'dd_custom_col_link', ... }
Acceptance Criteria
- A custom collections link can be added to a global collection