Two tables that references each other

How can I do two tables that references each other?

I have provided a minimal example to showcase what I am trying to achieve.
const table_1 = pgTable('table_1', {
    id: uuid('id').primaryKey().defaultRandom(),
    table_2_ref: uuid('table_1_ref').references(() => table_2.id)
});

const table_2 = pgTable('table_1', {
    id: uuid('id').primaryKey().defaultRandom(),
    table_1_ref: uuid('table_2_ref').references(() => table_1.id)
});


But when doing this I get a typescript error for both table_1 and table_2
'table_1' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

'table_2' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.


How can I solve this?
CleanShot_2024-05-23_at_12.06.402x.png
Was this page helpful?