Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drizzle Studio : There is not enough information to infer relation

I'm trying to launch drizzle studio but I get the following error :

Error: There is not enough information to infer relation "restaurantsTable.categories"

What have I done wrong ?

schema.ts

export const restaurantsTable = pgTable("restaurants", {
  id: serial("id").primaryKey(),
  [...]
});

export const restaurantTableRelations = relations(restaurantsTable, ({ one, many }) => ({
  menu: many(menuTable),
  categories: many(categoryTable, { relationName: 'categories' }),
}));

export const categoryTable = pgTable("categories", {
  id: serial("id").primaryKey(),
  restaurant_id: integer('restaurant_id').notNull()
});

export const categoryTableRelations = relations(categoryTable, ({ one }) => ({
  menu: one(menuTable, {
    fields: [categoryTable.restaurant_id],
    references: [menuTable.id],
    relationName: 'menu'
  })
}));
like image 257
Sowdowdow Avatar asked Nov 17 '25 15:11

Sowdowdow


1 Answers

Faced the same issue, turns out they're strict on defining the relationName on both sides as mentioned in here

Ensuring it's defined on both sides solved my issue

like image 50
Rami Maalouf Avatar answered Nov 19 '25 09:11

Rami Maalouf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!