Sowdowdow
Sowdowdow

Reputation: 291

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'
  })
}));

Upvotes: 21

Views: 9202

Answers (1)

Rami Maalouf
Rami Maalouf

Reputation: 311

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

Upvotes: 21

Related Questions