Drizzle Studio:没有足够的信息来推断关系

Sow*_*dow 6 postgresql drizzle sveltekit

我正在尝试启动 drizzle studio 但出现以下错误:

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

我做错了什么?

模式.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'
  })
}));
Run Code Online (Sandbox Code Playgroud)

小智 6

面临同样的问题,事实证明他们对relationName双方的定义都很严格,如此处提到的

确保双方都定义它解决了我的问题