22

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

1 Answer 1

21

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.