circular foreign keys
I have separate files for each table:
but this does not work, error:
How to fix it?
export const productVariant = pgTable("product_variant", {
id: serial("id").primaryKey(),
defaultPackageSizeId: integer("default_package_size_id")
.notNull()
.references(() => packageSize.id),
});
export const packageSize = pgTable("package_size", {
id: serial("id").primaryKey(),
productVariantId: integer("product_variant_id").references(
() => productVariant.id
),
});
export const productVariant = pgTable("product_variant", {
id: serial("id").primaryKey(),
defaultPackageSizeId: integer("default_package_size_id")
.notNull()
.references(() => packageSize.id),
});
export const packageSize = pgTable("package_size", {
id: serial("id").primaryKey(),
productVariantId: integer("product_variant_id").references(
() => productVariant.id
),
});
packageSize implicitly has type
because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
packageSize implicitly has type
because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
Solution:...Jump to solution
defaultPackageSizeId: integer("default_package_size_id").references(
(): AnyPgColumn => packageSize.id
),
defaultPackageSizeId: integer("default_package_size_id").references(
(): AnyPgColumn => packageSize.id
),
2 Replies