diff --git a/packages/drizzle/src/schema/traverseFields.ts b/packages/drizzle/src/schema/traverseFields.ts index 09fd865e4e0..d6c746a293a 100644 --- a/packages/drizzle/src/schema/traverseFields.ts +++ b/packages/drizzle/src/schema/traverseFields.ts @@ -450,8 +450,13 @@ export const traverseFields = ({ }, } - const baseForeignKeys: Record = { - _parentIdFk: { + // Skip creating a parent_id foreign key for blocks that are shared across collections (have a custom dbName) + const hasCustomDbName = block.dbName !== undefined && block.dbName !== null + const shouldSkipForeignKey = hasCustomDbName + + const baseForeignKeys: Record = {} + if (!shouldSkipForeignKey) { + baseForeignKeys._parentIdFk = { name: `${blockTableName}_parent_id_fk`, columns: ['_parentID'], foreignColumns: [ @@ -461,7 +466,7 @@ export const traverseFields = ({ }, ], onDelete: 'cascade', - }, + } } const isLocalized =